本文介绍了使用ggplot2在图的中心放置注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在几个ggplot对象的中心放置一个注释.
I'd like to place an annotation at the center of a several ggplot objects.
我已经研究并发现了一些类似的问题,例如:相对ggplot2中geom_text的位置?
I've researched and found a few similar questions such as here: Relative positioning of geom_text in ggplot2?
到目前为止,我发现的唯一答案是操纵绝对范围(例如,y = ymax/2").
So far, the only answer I've found is to manipulate the absolute range (e.g. ",y = ymax/2").
在打印到.pdf之前,我想在循环中添加注释层.我可以使用+/- Inf将批注放置在角落,如下所示:
I'd like to add the annotation layer in a loop, prior to printing to .pdf. I can place the annotation in the corners by using +/- Inf, as follows:
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()如何将注释放置在中心而不是角落?
How can I place the annotation at the center, rather than the corner?
推荐答案library(grid) # for textGrob qplot(1,1) + annotation_custom(grid::textGrob("there"), xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
更多推荐
使用ggplot2在图的中心放置注释
发布评论