gpt4 book ai didi

r - 并排绘制单个因子的多个点

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

这是我制作的示例数据和绘图。

library(ggplot2)  
value<-c(-1.01, -0.02,1.61,0.60, -0.98,0.19,4.68,-0.86,-3.52,-1.85,-2.08,-0.48,0.10,-1.05,-0.003)
sd<-c(1.40,0.48,0.83,0.41,0.80,0.36,1.52,0.30,1.19,0.44,1.33,0.45,0.64,0.35,1.20)
variable<-rep(c("A","B","C","D","E"),times=3)
clss<-rep(c("NC","RC","LC"),each=5)
df<-data.frame(value,variable,clss)

ggplot(df,aes(x=variable,y = value))+
geom_point()+
geom_hline(yintercept = 0, size = I(0.2), color = I("red")) +
geom_errorbar(aes(ymin = value - 1.96 * sd, ymax = value + 1.96 * sd),width = .1)
enter image description here
由于每个 A、B、C、D 和 E 有三个点,我想并排而不是在单个列中绘制这三个点。这也意味着我需要在标签 A 和 B、B 和 C 等之间留出一些间距,以便在图上分别看到 A、B、C、D 和 E 三个点。
我尝试使用抖动
enter image description here
但它只会改变我的观点,而不是我的误差线。此外,我需要将 A 放置在三点的中间。 B、C、D 和 E 类似。

最佳答案

您需要使用 dodge在两个 geom_pointgeom_errorbar :

ggplot(df,aes(x=variable,y = value,group=value,color=variable))+
geom_point(position=position_dodge(width=0.5)) +
geom_hline(yintercept = 0, size = I(0.2), color = I("red")) +
geom_errorbar(aes(x=variable,ymin = value - 1.96 * sd, ymax = value + 1.96 * sd),width = .1,position=position_dodge(width=0.5))

enter image description here

关于r - 并排绘制单个因子的多个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42754661/

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