0

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("")
EduardoSAS
  • 23
  • 3
  • This seems to be similar to this quetion. Have you checked it? http://stackoverflow.com/questions/2050610/creating-a-facet-wrap-plot-with-ggplot2-with-different-annotations-in-each-plot – Brani Apr 14 '10 at 09:03
  • I checked that one, but could not adapt it to my needs. When I plotted, the symbols still appeared on all facets – EduardoSAS Apr 15 '10 at 06:29

1 Answers1

2

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.

kohske
  • 65,572
  • 8
  • 165
  • 155
  • Thanks! With a little adaptation: geom_text(data=data.frame(Aspects=unique(Data1$Aspects),sig=c("","*","","","","","","*","")),aes(x=1,y=0.5,label=sig)) I got the stars where I wanted them to be! – EduardoSAS Apr 15 '10 at 06:39