My example is:
qplot(mtcars$mpg) +
annotate(geom = "text", x = 30, y = 3, label = "Some text\nSome more text")
How do I get the text here to be left aligned? So that the 'Some's line up with each other.
My example is:
qplot(mtcars$mpg) +
annotate(geom = "text", x = 30, y = 3, label = "Some text\nSome more text")
How do I get the text here to be left aligned? So that the 'Some's line up with each other.
hjust = 0
does what you want. hjust stands for horizontal justification, 0 will be left-justified, 0.5 will be centered, and 1 will be right-justified.See also
vjust
for vertical justification.In
ggplot2
, these arguments are present any time text preferences are set. They work forannotate
,geom_text
, or inelement_text
when adjusting theme options.If you look at
?geom_text
, you can find text string options:"left"
,"middle"
, or"right"
, (forhjust
),"top"
,"center"
,"bottom"
forvjust
, and for either"inward"
and"outward"
which will always adjust in toward or out away from the center.This behavior is similar in many
base
graphics functions, such as theadj
argument forpar
, used bytext()
,mtext()
, andtitle()
, which can be vector of length 2 for the horizontal and vertical justificatons. Also thehadj
andpadj
arguments toaxis()
for justifications horizontal to and perpendicular to the axis.