gpt4 book ai didi

R ggplot geom_errorbar 不显示 mustache

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

使用 ggplot 在 R 中绘制我的数据,不显示错误栏 mustache 。为什么不显示 mustache ?如何解决才能显示它们?

(虽然没有必要在 geom_errorbar 中指定“data=...”,但我使用较小的数据集在较大的数据集之上绘制了几个点及其误差条。我在这里进行了简化只对所有内容使用较小的数据框,但想让这个示例接近我打算使用的代码。)

谢谢!肖娜

shapes <- c(1, 19, 15, 1, 0)
names(shapes) <- levels(smallDF$Treatment)

p <- ggplot(data=smallDF, aes(x=pNew, y=diff, group=Treatment))
p <- p + geom_errorbar(data=smallDF, aes(ymin=diff-se,ymax=diff+se),
color="black", width=.3, position=position_dodge(.5))
p <- p + geom_line(size=.3)
p <- p + geom_point(data=smallDF, aes(shape=Treatment),fill="white",
size=2.5)
#p <- p + scale_shape_manual(values=c(1, 19, 15, 1, 0))
p <- p + scale_shape_manual(values=shapes)
p <- p + xlab("Pressure (mmHg)") + ylab("delD (mm)")
p <- p + theme_bw()
p <- p + theme(
legend.position="none"
# , axis.text.y=element_blank()
# , axis.title.y=element_blank()
, panel.border=element_blank()
, axis.line = element_line(colour = "black")
, axis.text.x = element_text(size=10)
, axis.text.y = element_text(size=10)
, axis.title.x= element_text(size=10)
, axis.title.y= element_text(size=10)
, strip.text.x = element_text(size = 10)
)
p

enter image description here

Treatment   step    N   diff    sd  se  ci  predictD    pNew
cntl 2 7 0.256537749 0.130605763 0.049364339 0.120790185 1.483185156 10
cntl 3 7 0.317586245 0.151444256 0.057240549 0.140062577 1.626590815 15
cntl 4 7 0.377309785 0.165262839 0.062463482 0.152842634 1.788401781 20
cntl 5 7 0.433531627 0.173735352 0.065665791 0.160678402 1.964393744 25
cntl 6 7 0.467529177 0.171603123 0.064859884 0.158706419 2.142879696 30
cntl 7 7 0.441401156 0.163740786 0.0618882 0.15143497 2.291729181 35
cntl 8 7 0.360578168 0.143967074 0.054414439 0.133147337 2.402152991 40
cntl 9 7 0.263484929 0.117425017 0.044382485 0.108600028 2.481824239 45
cntl 10 7 0.172079736 0.094209661 0.035607905 0.087129405 2.53504158 50
cntl 11 7 0.081780331 0.070316765 0.026577239 0.065032161 2.561500546 55
cntl 12 7 0.172079736 0.094209661 0.035607905 0.087129405 2.53504158 50
cntl 13 7 0.263484929 0.117425017 0.044382485 0.108600028 2.481824239 45
cntl 14 7 0.360578168 0.143967074 0.054414439 0.133147337 2.402152991 40
cntl 15 7 0.441401156 0.163740786 0.0618882 0.15143497 2.291729181 35
cntl 16 7 0.467529177 0.171603123 0.064859884 0.158706419 2.142879696 30
cntl 17 7 0.433531627 0.173735352 0.065665791 0.160678402 1.964393744 25
cntl 18 7 0.377309785 0.165262839 0.062463482 0.152842634 1.788401781 20
cntl 19 7 0.317586245 0.151444256 0.057240549 0.140062577 1.626590815 15
cntl 20 7 0.256537749 0.130605763 0.049364339 0.120790185 1.483185156 10
3hpx 2 6 0.124643574 0.068765439 0.028073373 0.072164903 1.511618688 10
3hpx 3 8 0.121806932 0.088542241 0.03130441 0.074023166 1.537544183 15
3hpx 4 8 0.138107729 0.097228081 0.034375318 0.08128471 1.602344034 20
3hpx 5 8 0.149529 0.10158369 0.035915258 0.08492609 1.665227481 25
3hpx 6 8 0.157687817 0.101898303 0.036026491 0.085189113 1.724788023 30
3hpx 7 8 0.154261671 0.099724849 0.035258058 0.08337206 1.776475381 35
3hpx 8 8 0.140631071 0.091483297 0.03234423 0.07648195 1.819131367 40
3hpx 9 8 0.123241311 0.083112381 0.029384664 0.069483689 1.854326249 45
3hpx 10 8 0.103092334 0.075467614 0.026681831 0.063092504 1.882440312 50
3hpx 11 8 0.080332775 0.070303352 0.024855989 0.058775073 1.903587298 55
3hpx 12 8 0.103092334 0.075467614 0.026681831 0.063092504 1.882440312 50
3hpx 13 8 0.123241311 0.083112381 0.029384664 0.069483689 1.854326249 45
3hpx 14 8 0.140631071 0.091483297 0.03234423 0.07648195 1.819131367 40
3hpx 15 8 0.154261671 0.099724849 0.035258058 0.08337206 1.776475381 35
3hpx 16 8 0.157687817 0.101898303 0.036026491 0.085189113 1.724788023 30
3hpx 17 8 0.149529 0.10158369 0.035915258 0.08492609 1.665227481 25
3hpx 18 8 0.138107729 0.097228081 0.034375318 0.08128471 1.602344034 20
3hpx 19 8 0.121806932 0.088542241 0.03130441 0.074023166 1.537544183 15
3hpx 20 6 0.124643574 0.068765439 0.028073373 0.072164903 1.511618688 10

最佳答案

我将您的 width = 0.3 更改为 width = 5。我还删除了您拥有的所有冗余 data = smallDF,并将您单独设置的字体大小替换为 theme_bw()base_size 参数。

p <- ggplot(data = smallDF, aes(x = pNew, y = diff, group = Treatment)) +
geom_errorbar(aes(ymin = diff - se, ymax = diff + se),
color = "black",
width = 5, ## This is the width of the crossbars!
position = position_dodge(.5))
geom_line(size = .3)
geom_point(aes(shape = Treatment),
fill = "white", size = 2.5) +
scale_shape_manual(values = shapes) +
xlab("Pressure (mmHg)") +
ylab("delD (mm)") +
theme_bw(base_size = 10) +
theme(
legend.position="none"
, panel.border=element_blank()
, axis.line = element_line(colour = "black")
)
p

enter image description here

关于R ggplot geom_errorbar 不显示 mustache ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36578083/

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