在我的情节中,我既有图例也有文字注释。对于传说,我可以指定
legend.justification=c(1,0), legend.position=c(1,0)
定位相对于绘图区域的位置(例如,右上角,左下角)。但是,当我放置一个注释层(http://docs.ggplot2.org/0.9.3.1/annotate.html)时,似乎只能指定文本的坐标
annotate("text", x = 8e-7, y = 1e-5, label=data.note, size = 5)
而不是绘图区域的位置(我想将文本放在左下角)。文本的长度(label)对于不同的情节可能有所不同。有没有办法做到这一点?谢谢!

最佳答案

这是您要找的东西吗?

set.seed(1)
df <- data.frame(x=rnorm(100),y=rnorm(100))
ggplot(df, aes(x,y)) +geom_point()+
  annotate("text",x=min(df$x),y=min(df$y),hjust=.2,label="Text annotation")

可能需要对hjust=...进行一些实验,才能将其准确地放在左下角。

关于r - ggplot2注释层在R中的位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22488563/

10-12 20:04