可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am trying to plot a simple scatter plot for 3 groups, overlaying a segment indicating the mean for each group and labelling the groups. I have managed to get a scatter plot with error bars, but I would only like a segment indicating where the mean is. I also cannot seem to be getting the group labelling right.
To get the summary statistics I am using the function "summarySE" from this page.
Is there any simpler way to do this, and to get a segment instead of a point for the mean?
I really appreciate your help!
library(ggplot2) library(plyr) df
回答1:
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"))

回答2:
To get the group labelling , You can change continuous tt a factor like this :
dfc$tt
Of course before calling summarySE
and creating dfc
.
and using crossbar
as mentioned in the other solution below , you get:
