2010-03-23 21 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") 

希望這有助於。結果看起來非常乾淨,這是我認爲你想要的。