我想在几个ggplot对象的中心放置一个注释.
我研究过并发现了一些类似的问题,例如:ggplot2中geom_text的相对定位?
到目前为止,我发现的唯一答案是操纵绝对范围(例如",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()
Run Code Online (Sandbox Code Playgroud)
如何将注释放在中心而不是角落?
library(grid) # for textGrob
qplot(1,1) +
annotation_custom(grid::textGrob("there"),
xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
Run Code Online (Sandbox Code Playgroud)
