2015-10-19 18 views
0

如何在R中的一個圖上繪製多個自舉置信區間? 我用置信區間的下限和上限創建了一個Excel文檔。我想要一個陰謀,每年有兩個置信區間(線或框將罰款)在兩種顏色來表示組A或B.如何在一張圖上顯示多個自舉置信區間

我試圖使用bwplot功能,但我試過的代碼didn'工作。

bwplot(Lower+Upper~Year, data=yeargroupboot) 

數據:

Year  Upper  Lower Site 
2001  123  121  A 
2001  115  113  B 
2002  127  124  A 
2002  114  113  B 
2003  145  141  A 
2003  100  99  B 

回答

0
  • 我不能完全得到bwplot工作,你想要的方式:bwplot(Lower+Upper~factor(Year)|Site,data=dd)是我
  • 您可以使用plotCI(從plotrix或最接近gplots包)手動完成;
  • 或使用ggplot2如下:

構造數據:

dd <- read.table(header=TRUE,text=" 
    Year  Upper  Lower Site 
    2001  123  121  A 
    2001  115  113  B 
    2002  127  124  A 
    2002  114  113  B 
    2003  145  141  A 
    2003  100  99  B ") 

library("ggplot2"); theme_set(theme_bw()) 
ggplot(dd)+ 
    geom_linerange(aes(Year,ymin=Lower,ymax=Upper,colour=Site), 
        position=position_dodge(width=0.25))+ 
    scale_x_continuous(breaks=2001:2003) 
+0

太感謝你了! – MythicalS