【问题标题】:Creating a facet_wrap plot with ggplot2 with less annotations than plots使用 ggplot2 创建一个 facet_wrap 图,其注释少于图
【发布时间】:2011-02-07 19:41:32
【问题描述】:

我正在使用 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("")

【问题讨论】:

  • 这似乎与这个问题相似。你检查过吗? stackoverflow.com/questions/2050610/…
  • 我检查了那个,但无法适应我的需要。当我绘制时,符号仍然出现在所有方面

标签: r graph ggplot2 facet-wrap


【解决方案1】:

这将是一个最小的示例。 重要的是 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。

【讨论】:

  • 谢谢!稍加修改: geom_text(data=data.frame(Aspects=unique(Data1$Aspects),sig=c("","","","","","","", "","")),aes(x=1,y=0.5,label=sig)) 我得到了我想要的星星!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-16
  • 1970-01-01
  • 1970-01-01
  • 2013-01-28
相关资源
最近更新 更多