gpt4 book ai didi

r - 如何重现置信区间图?

转载 作者:行者123 更新时间:2023-12-04 09:46:04 25 4
gpt4 key购买 nike

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

enter image description here

最佳答案

没有上下文和可重复的例子,很难给出一个好的答案。不过我觉得剧情很有意思。

这是我对 ggplot2 的尝试。我仍然对 alpha layer 有一些问题,但情节的主要思想在这里。

一些数据

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")

数据看起来像这样

日期
  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

这是结果

enter image description here
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")

关于r - 如何重现置信区间图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13773806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com