使用ggplot2在图的中心放置注释

编程入门 行业动态 更新时间:2024-10-15 08:18:41
本文介绍了使用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在图的中心放置注释

本文发布于:2023-11-30 03:05:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648512.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注释   中心

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!