I am starting to use ggplot2. I have some small n (about 30 or so) granular data with lots of overlap. Neither jitter nor alpha (transparency) are suitable. Instead a stripchart with stack and offset do it best but I do not know how to do it in ggplot2. Do you know?
To see what the end result should be click on this graphic.
Here is the script I used a few years ago.
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")
If you use a scatter plot for a dataset that has discrete values in one dimension, for example your x-axis shows the days of the week, you can get points overlapping when you plot the data. To make the chart easier to interpret you can introduce jitter to the data points.
Fixes for overplotting include reducing the size of points, changing the shape of points, jittering, tiling, making points transparent, only showing a subset of points, and using algorithms to prevent labels from overlapping.
How would you like both points to be displayed? A common workaround for this kind of overplotting situation is to give the markers an opacity < 1 so that overlapping points are darker. Opacity is controlled by the scatter. marker.
You can use 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
# 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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With