如何在一张图上显示多个 bootstrap 置信区间

How to display several bootstrap confidence intervals on one plot

如何在 R 中的一个图上绘制多个 bootstrap 置信区间? 我创建了一个 Excel 文档,其中包含置信区间的下限和上限。我想要一个图,其中每年有两个置信区间(线或框都可以)用两种颜色表示 A 组或 B 组。

我尝试使用 bwplot 函数,但我尝试的代码不起作用。

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  
  • 我无法完全bwplot按照您想要的方式工作:bwplot(Lower+Upper~factor(Year)|Site,data=dd) 是我最接近的
  • 您可以使用 plotCI(来自 plotrixgplots 包)手动执行此操作;
  • 或使用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)