Two dots for outliers when geom_boxplot() + geom_jitter()

719 views
Skip to first unread message

Mickey

unread,
Apr 8, 2012, 7:48:03 AM4/8/12
to ggplot2
Hi,

Is it the expected result that two dots are plotted for outliers, one
on the center line and the other as jittered, when we plot with
geom_boxplot() + geom_jitter() ?

p <- ggplot(mtcars, aes(factor(cyl), mpg))
p + geom_boxplot() + geom_jitter()

sort(mtcars[mtcars$cyl==8,'mpg'])
# [1] 10.4 10.4 13.3 14.3 14.7 15.0 15.2 15.2 15.5 15.8 16.4 17.3 18.7
19.2

We can see 3 dots for 10.4 of cyl==8 and 2 dots for 19.2.
(see http://had.co.nz/ggplot2/geom_boxplot.html)

Mickey

Brandon Hurr

unread,
Apr 8, 2012, 9:33:06 AM4/8/12
to Mickey, ggplot2
geom_boxplot is outputting the outliers and geom_jitter is outputting the same points over again. 

The points below the box are 10.4 as an outlier (center line) and then 10.4 and 10.4 to the left and right from geom_jitter(). 

Above the boxplot on cyl==8 you've got the outlier 18.7 on the center line from geom_boxplot and then 18.7 and 17.3 from geom_jitter(). 

You can see it easier if you do this. 

p <- ggplot(mtcars, aes(factor(cyl), mpg))
p + geom_boxplot() + geom_jitter(outlier.colour="NA")

This erases the outliers from the geom_boxplot output. 

HTH, 
B


Mickey

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Winston Chang

unread,
Apr 8, 2012, 10:27:18 AM4/8/12
to Brandon Hurr, Mickey, ggplot2
You can see it easier if you do this. 

p <- ggplot(mtcars, aes(factor(cyl), mpg))
p + geom_boxplot() + geom_jitter(outlier.colour="NA")


I think you mean:
p <- ggplot(mtcars, aes(factor(cyl), mpg))
p + geom_boxplot(outlier.colour=NA) + geom_jitter()

Brandon Hurr

unread,
Apr 8, 2012, 10:29:48 AM4/8/12
to Winston Chang, Mickey, ggplot2
Yes, should have copy and pasted it from the GUI. =\
Reply all
Reply to author
Forward
0 new messages