2010-03-23 22 views
6

我开始使用ggplot2。我有一些小的n(大约30左右)粒子数据,有很多重叠。无论是抖动还是Alpha(透明度)都不适合。相反,带有堆栈和偏移量的条形图可以做到最好,但我不知道如何在ggplot2中做到这一点。你知道吗?如何克服ggplot2中没有抖动或透明度的重叠点

要看最终结果应该点击这个graphic

这是我几年前使用的脚本。

stripchart(SystData$DayTo1Syst~SystData$strain,vertical=TRUE,method="stack",pch=19,offset=.3,xlab="Strain",main="Rapidity of Systemic Disease Onset",ylab="Days post inoculation") 
+0

这只是x轴上的抖动吗? – 2010-03-23 18:58:12

+0

是的。抖动只会在x轴上,但我实际上不需要抖动。我更喜欢从左到右的有序进展。 – Farrel 2010-03-23 21:20:42

+0

向日葵阴谋可以在这里工作得很好,但我不知道用ggplot2创建它们有多简单。 – 2010-03-24 11:26:06

回答

6
# your data 
df <- data.frame(gp = rep(LETTERS[1:5], each =8), y = sample(1:4,40,replace=TRUE)) 
# calculate offsets 
df <- ddply(df, .(y, gp), transform, offset = (1:length(gp)-1)/20) 
qplot(gp, y, data=df) + stat_identity(aes(as.numeric(gp)+offset)) + theme_bw() 
8

您可以使用position_dodge

df <- data.frame(gp = rep(LETTERS[1:5], each =8), 
       y = sample(1:4,40,replace=TRUE)) 
qplot(gp,y,data=df,order=y,position=position_dodge(width=0.5)) 

alt text http://img100.imageshack.us/img100/8760/dodgel.png

+1

如果仔细观察,这不是Farrel想要的:位置闪避传播所有点数,而示例数字只传播超量点数 – xiechao 2010-03-25 00:39:57

4

你想用geom_dotplot从GGPLOT2

你可能会想使用:

ggplot(insert your arguments here) + geom_dotplot(binaxis = "y", stackdir = "center") 

希望这有助于。结果看起来非常干净,这是我认为你想要的。