[英] How to left align text in annotate from ggplot2
我的例子是:
qplot(mtcars$mpg) +
annotate(geom = "text", x = 30, y = 3, label = "Some text\nSome more text")
如何让这里的文本左对齐?这样他们就可以排成一排了.
我的例子是:
qplot(mtcars$mpg) +
annotate(geom = "text", x = 30, y = 3, label = "Some text\nSome more text")
如何让这里的文本左对齐?这样他们就可以排成一排了.
hjust = 0
是你想要的.hjust代表horizontal justification,0将左对齐,0.5将居中,1将右对齐.
qplot(mtcars$mpg) +
annotate(geom = "text", x = 30, y = 3,
label = "Some text\nSome more text",
hjust = 0)
垂直对正见vjust
.
在ggplot2
中,每当设置文本首选项时,这些参数都会出现.在调整主题选项时,它们适用于annotate
、geom_text
或element_text
.
如果你看?geom_text
,你可以找到文本字符串选项:"left"
、"middle"
或"right"
(对于hjust
)、"top"
、"center"
、"bottom"
或vjust
,以及"inward"
和"outward"
中的任何一个,它们总是朝着中心或远离中心进行调整.
这种行为在许多base
个图形函数中类似,例如text()
、mtext()
和title()
使用的par
的adj
参数,对于水平和垂直对正符号,它可以是长度为2的向量.此外,hadj
和padj
对axis()
的论点也证明了h与轴线平行,p与轴线垂直.