R graphic:移动不同系列的值,使误差条不重叠

时间:2013-05-09 07:53:09

标签: r graph ggplot2

这是一段代码:

set.seed (12)
library(ggplot2)
dat = data.frame(a=runif(40,0,1),b=c('a','b','c','d','e'),c=c('Hi','Hello'))
ggplot(dat,aes(x=b,y=a,shape=factor(c))) + stat_summary(fun.data=mean_cl_normal)

它创建的图形具有重叠的误差条,因此很难区分限制。我经常看到图形,其中不同的系列(由因子c给出)略微水平移动,因此误差条不重叠。在x中使用分类变量时,有没有办法用R来实现这个?

谢谢

1 个答案:

答案 0 :(得分:3)

您可以使用position_dodge()

之类的内容
ggplot(dat,aes(x=b,y=a,shape=factor(c))) +
  stat_summary(fun.data=mean_cl_normal, position=position_dodge(width=0.2))

示例图:

enter image description here