如何重现置信区间图?

Bor*_*lis 4 graphics r confidence-interval

我需要重现类似于附加图像的图形.我希望使用图形来比较比例之间差异的置信区间.如何使用R生成附加图形?任何指向正确的方向将不胜感激.

在此输入图像描述

ags*_*udy 8

没有上下文和可重复的例子,很难给出一个好的答案.但我认为情节很有趣.

在这里我尝试使用ggplot2.我仍然对alpha图层有一些问题,但是这个图的主要思想就在这里.

一些数据

structure(list(scen = 1:6, 
               name = c("I", "II", "III", "IV", "V","VI"), 
               ymin = c(0.06, -0.102, 0.487, 0.116, -0.436, 0.021), 
               ymax = c(-0.231,0.135, 0.117, 0.338, -0.347, -0.025)), 
          .Names = c("scen", "name", "ymin", "ymax"), 
          row.names = c(NA, 6L), 
          class = "data.frame")
Run Code Online (Sandbox Code Playgroud)

数据看起来像这样

DAT

  scen name   ymin   ymax   y
1    1    I  0.060 -0.231   I
2    2   II -0.102  0.135  II
3    3  III  0.487  0.117 III
4    4   IV  0.116  0.338  IV
5    5    V -0.436 -0.347   V
6    6   VI  0.021 -0.025  VI
Run Code Online (Sandbox Code Playgroud)

这是结果

在此输入图像描述

theme_new <- theme_set(theme_bw())
p <- ggplot(data=dat) +
  geom_segment(aes(x=ymin,y=scen,xend=ymax,yend=scen),
               arrow=arrow(length=unit(0.3,"cm"),
                           ends='both'),size=1) 

p <- p+  geom_rect(xmin=max(dat$ymin)/2,
                    xmax=min(dat$ymax)/2,
                    ymin=0,
                    ymax=max(dat$scen)+1,
                    alpha=0.2,fill='grey')

p <- p + geom_text(aes(x=(ymin+ymax)/2,
                       y=scen+0.2,label =name),size=6)

p<- p + coord_cartesian(ylim=c(0,max(dat$scen)+3))+
  xlab(expression(P[1]-P[0]))+
  theme( 
    axis.ticks = element_blank(),
    axis.text.y = element_blank(),
    axis.text.x = element_blank(),
    axis.title.x = element_text(face="bold",  size=20))

p <- p + geom_vline(linetype   ='dashed',
                    xintercept = mid.dash)

p <- p + geom_text(aes(x= mid.dash,
                       y = max(dat$scen)+2, 
                       label="Zone of Indifference", 
                       color="NA*"),rotate=180)
p <- p + theme(legend.position = "none")
Run Code Online (Sandbox Code Playgroud)

p