【发布时间】:2012-05-16 14:38:56
【问题描述】:
我正在尝试从 GGplot2 研讨会 http://dl.dropbox.com/u/42707925/ggplot2/ggplot2slides.pdf 重新创建一个图形。
在这种情况下,我正在尝试生成示例 5,其中抖动的数据点会受到闪避。当我运行代码时,这些点以正确的线为中心,但没有抖动。
这是直接来自演示文稿的代码。
set.seed(12345)
hillest<-c(rep(1.1,100*4*3)+rnorm(100*4*3,sd=0.2),
rep(1.9,100*4*3)+rnorm(100*4*3,sd=0.2))
rep<-rep(1:100,4*3*2)
process<-rep(rep(c("Process 1","Process 2","Process 3","Process 4"),each=100),3*2)
memorypar<-rep(rep(c("0.1","0.2","0.3"),each=4*100),2)
tailindex<-rep(c("1.1","1.9"),each=3*4*100)
ex5<-data.frame(hillest=hillest,rep=rep,process=process,memorypar=memorypar, tailindex=tailindex)
stat_sum_df <- function(fun, geom="crossbar", ...) {stat_summary(fun.data=fun, geom=geom, ...) }
dodge <- position_dodge(width=0.9)
p<- ggplot(ex5,aes(x=tailindex ,y=hillest,color=memorypar))
p<- p + facet_wrap(~process,nrow=2) + geom_jitter(position=dodge) +geom_boxplot(position=dodge)
p
【问题讨论】:
-
鉴于 Didzis Elferts 使用 ggplot2 1.0.0 版中提供的
position_jitterdodge提供了更好的答案,您应该不接受我的答案并接受 Didzis Elferts 提供的答案。