【发布时间】:2014-08-25 14:24:50
【问题描述】:
我想在几个 ggplot 对象的中心放置一个注释。
我研究并发现了一些类似的问题,例如:Relative positioning of geom_text in ggplot2?
到目前为止,我找到的唯一答案是操纵绝对范围(例如“,y = ymax/2”)。
我想在打印到 .pdf 之前循环添加注释层。我可以使用 +/- Inf 将注释放在角落,如下所示:
plot.list<-list()
g<- qplot(1,1)
plot.list[[length(plot.list)+1]]<-g
plot.list[[length(plot.list)+1]]<-g
pdf("MyReport.pdf"
,width = 14
,height=8.5
,paper="a4r")
for(i in 1:length(plot.list)){
print(plot.list[[i]]+
annotate("text",x=Inf,y=Inf,hjust=1,vjust=1
,label="PLEASE DO NOT DISTRIBUTE"
,fontface="bold",color="darkred",alpha=0.3))
}
dev.off()
如何将注释放在中心而不是角落?
【问题讨论】:
-
annotation_customshould work -
@baptiste - 感谢您为我指明正确的方向。 annotation_custom 的帮助文本不清楚如何进行非相对定位(即不依赖数据)。我正在尝试类似: plot.list[[i]]+annotation_custom(grob=splitTextGrob("PRELIMINARY, PLEASE DO NOT DISTRIBUTE"),xmin = 1,xmax=5, ymin = 1, ymax=100) 但是这个仍然依赖于 x 和 y 尺度
-
如果您使用 +/- Inf 作为限制,则 grob 应该跨越整个情节,因此文本应该位于中心