并排绘制单个因素的多个点

Plot multiple points of a single factor side by side

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

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)

因为每个 A、B、C、D 和 E 都有三个点,所以我想并排绘制这三个点而不是在一列中。这也意味着我需要在标签 A 和 B、B 和 C 等之间留出一些间距,以便在图表上分别看到 A、B、C、D 和 E 的三个点。

我尝试使用抖动

但这只会改变我的观点,不会改变我的误差线。此外,我需要将 A 放置在三个点的中间。对于 B、C、D 和 E 也是如此。

您需要在 geom_pointgeom_errorbar 上使用 dodge:

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