ken*_*nyB 75 r annotate text-alignment ggplot2
我的例子是:
qplot(mtcars$mpg) + annotate(geom = "text", x = 30, y = 3, label = "Some text\nSome more text")
Run Code Online (Sandbox Code Playgroud)
如何让这里的文字保持对齐?所以'有些人相互排队.
Gre*_*gor 115
hjust = 0
做你想要的.hjust代表水平对齐,0表示左对齐,0.5表示居中,1表示右对齐.
qplot(mtcars$mpg) +
annotate(geom = "text", x = 30, y = 3,
label = "Some text\nSome more text",
hjust = 0)
Run Code Online (Sandbox Code Playgroud)
另请参阅vjust
垂直对齐.
在ggplot2
,任何时候设置文本首选项时都会出现这些参数.他们的工作进行annotate
,geom_text
或在element_text
调整主题选项时.
如果你看一下?geom_text
,你可以找到文本字符串选项:"left"
,"middle"
,或"right"
,(对于hjust
)"top"
,"center"
,"bottom"
对vjust
,和任何"inward"
和"outward"
这将永远朝向或从中心向外远离调整英寸
这种现象是在许多类似的base
图形功能,如adj
对参数par
,通过使用text()
,mtext()
和title()
,其可以是长度为2的向量的水平和垂直justificatons.另外,hadj
和padj
参数axis()
为理由ħ orizontal到和p erpendicular于轴线.