开发者

Creating a facet_wrap plot with ggplot2 with less annotations than plots

I am using ggplot2 t开发者_如何学Goo 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("")


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜