Categorical scatter plot with mean segments using ggplot2 in R

你说的曾经没有我的故事 提交于 2019-11-28 10:35:35

You can use geom_crossbar() and use val as y, ymin and ymax values. With scale_x_continuous() you can change x axis labels for original data or use @agstudy solution to change original data and labels will appear automatically.

ggplot()+
  geom_jitter(aes(tt, val), data = df, colour = I("red"), 
              position = position_jitter(width = 0.05)) +
  geom_crossbar(data=dfc,aes(x=tt,ymin=val, ymax=val,y=val,group=tt), width = 0.5)+
  scale_x_continuous(breaks=c(1,2,3),labels=c("Group1", "Group2", "Group3"))

To get the group labelling , You can change continuous tt a factor like this :

dfc$tt <- factor(dfc$tt,labels=c("Group1", "Group2", "Group3"))

Of course before calling summarySE and creating dfc.

and using crossbar as mentioned in the other solution below , you get:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!