使用 ggplot2 创建 facet_wrap 图,注释比图少

发布于 2024-08-29 11:44:09 字数 722 浏览 3 评论 0原文

我正在使用 ggplot2 绘制包含九个面的图形。每个方面代表两个变量之间的关系,我想用星号“”注释显示统计显着结果的方面。这将导致九个面中只有两个带有“”。然而,我最终得到了显示注释的所有九个方面。

我该如何解决这个问题?

library(ggplot2)

Sig<-c("","*","","","","","","*","") # Only the second and the second to last facets should receive significance stars.
Data.annot<-data.frame(unique(Aspects),Sig)

qplot(Labels,Es,data=Data1) + geom_pointrange(aes(x=Labels,y=Es,ymin=Low,ymax=Up)) + geom_hline(yintercept=0, linetype="dashed") + coord_flip() + facet_wrap(~Aspects, scales="free") + geom_text(data=Data.annot, aes(x= 0.5, y= 1, label = Sig)) + scale_y_continuous("Correlation coefficient\n(effect size)",limits=c(-0.5,1),breaks=c(-0.5,0,0.5,1.0)) + scale_x_discrete("")

I am using ggplot2 to plot a figure that contains nine facets. Each facet represents the relationship between two variables and I would like to annotate the facets that display statistically significant results with a star ''. This would result in only two of the nine facets with a ''. However, I end up with all nine facets displaying the annotation.

How can I fix this?

library(ggplot2)

Sig<-c("","*","","","","","","*","") # Only the second and the second to last facets should receive significance stars.
Data.annot<-data.frame(unique(Aspects),Sig)

qplot(Labels,Es,data=Data1) + geom_pointrange(aes(x=Labels,y=Es,ymin=Low,ymax=Up)) + geom_hline(yintercept=0, linetype="dashed") + coord_flip() + facet_wrap(~Aspects, scales="free") + geom_text(data=Data.annot, aes(x= 0.5, y= 1, label = Sig)) + scale_y_continuous("Correlation coefficient\n(effect size)",limits=c(-0.5,1),breaks=c(-0.5,0,0.5,1.0)) + scale_x_discrete("")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁以何悠 2024-09-05 11:44:09

这将是一个最小的例子。
重要的是 geom_text 的数据。

dat<-data.frame(fa=gl(4,3),x=runif(12),y=runif(12))
q<-ggplot(dat,aes(x=x,y=y))+geom_point()+facet_wrap(~fa)+
geom_text(data=data.frame(fa=gl(4,1),sig=c("","*","","+")),aes(x=0.5,y=0.5,label=sig))
print(q)

HTH。

This would be a minimum example.
What is important is the data for geom_text.

dat<-data.frame(fa=gl(4,3),x=runif(12),y=runif(12))
q<-ggplot(dat,aes(x=x,y=y))+geom_point()+facet_wrap(~fa)+
geom_text(data=data.frame(fa=gl(4,1),sig=c("","*","","+")),aes(x=0.5,y=0.5,label=sig))
print(q)

HTH.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文