2010-04-14 115 views
0

我正在使用ggplot2繪製包含九個構面的圖。每個方面代表兩個變量之間的關係,我想用明星''來標註顯示統計顯着結果的方面。這會導致只有兩個''的九個方面。但是,我最終將顯示註釋的所有九個方面。使用ggplot2創建facet_wrap圖,註釋少於註解

我該如何解決這個問題?

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("") 
+0

這似乎與這個佇列相似。你檢查過了嗎? http://stackoverflow.com/questions/2050610/creating-a-facet-wrap-plot-with-ggplot2-with-different-annotations-in-each-plot – Brani 2010-04-14 09:03:42

+0

我檢查了一個,但無法適應我的需要。當我繪製時,符號仍然出現在所有方面 – EduardoSAS 2010-04-15 06:29:26

回答

2

這將是一個最小的例子。 重要的是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

謝謝!稍作修改: geom_text(data = data.frame(Aspects = unique(Data1 $ Aspects),sig = c(「」,「*」,「」,「」,「」,「」,「」, 「*」,「」)),aes(x = 1,y = 0.5,label = sig)) 我得到了我希望他們成爲的星星! – EduardoSAS 2010-04-15 06:39:45