我用vjust
作为解决方法,并通过尝试和错误的阐述可接受 距离。但是,这有时非常耗时,并且使用字体大小和轴比例来更改 。对齐geom_text到geom_vline在GGPLOT2
有没有更好的方法来对齐示例中的文本自动?
library(ggplot2)
ggplot(data=mtcars, aes(x=hp, y=mpg))+
geom_point()+
theme_bw() +
geom_vline(xintercept=200, colour="grey") +
geom_text(aes(x=200, label="the strong cars", y=20), colour="blue", angle=90, vjust = 1.2, text=element_text(size=11))+
geom_text(aes(x=200, label="the weak cars", y=20), colour="red", angle=90, vjust = -1, text=element_text(size=11))
ggsave(filename="geomline.png", width=5.5, height=2*3, dpi=300)
你想如何对齐? vjust = 0和vjust = 1似乎做了他们应该做的事情,超出这个范围的值总是比较偏心。 – baptiste
我希望计算机看起来字体大小并将文本框放在正确的距离。因此,用户不必玩弄vjust值。 –
我认为自动定位标签会很难,即使情节总是很简单。你看过['directlabels'](http://cran.r-project.org/web/packages/directlabels/index.html)包吗? – SlowLearner