[R] Stripchart and Boxplots side-by-side

Karl Ove Hufthammer Karl.Hufthammer at math.uib.no
Thu May 22 14:59:45 CEST 2008


Dieter Wirz:

> with(InsectSprays, boxplot(count ~ spray, boxwex = 0.3))
> with(InsectSprays, stripchart(count ~ spray, col = "red", vertical =
> TRUE, add = TRUE))
> 
> But the dots from the stripchart are plotted over the Boxes.
> Is there any possibility to have Stripchart and Boxplots side-by-side,
> i.e. to move boxplots and/or stripcharts a bit to the left or right?

It's likely *possible*, but I think it might look a bit confusing.
Your original example is OK, but I propose you change the plotting 
function you use. The following looks pretty good to me, and much
better than your original, IMHO.

library(ggplot2)
g = ggplot(InsectSprays, aes(x=spray, y=count))
g + geom_boxplot() + geom_point(colour="red", position="jitter")

Image at:
http://www.uib.no/People/st11188/r/r-help/images/insectsprays-boxplot-stripchart.png

Here I've used jittering to make all of the observations visible.
You *did* notice that a lot of observations were overplotted in
your original graph, right? ;-)

Another solution would be to create two graphs side by side,
one boxplot and one stripchart.

-- 
Karl Ove Hufthammer



More information about the R-help mailing list