I need to reproduce a graph similar to the attached image. I hope to use the graphic to compare confidence intervals of the difference between proportions. How can I produce the attached graphic using R? Any pointers in the right direction would be appreciated.
Without context and a reproducible example it is hard to give a good answer. But I think the plot is interesting.
Here my attempt with ggplot2. I still have some problem with alpha layer , but the main idea of the plot is here.
Some data
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")
The data look like this
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
This is the result
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")
p
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With