R-ecology-lesson icon indicating copy to clipboard operation
R-ecology-lesson copied to clipboard

Plotting with ggplot2 --> geom_boxplot + geom_jitter note

Open dakirsc opened this issue 2 years ago • 1 comments

My comment is specifically about the example code showing how to add points to a ggplot boxplot. It's possible this is something that was fixed in an update to R or the ggplot2 package, but I know historically there have been issues with using geom_jitter and geom_boxplot together and these combined functions causing outlier points to duplicate.

I realize the code in the episode takes care of this by including geom_boxplot(alpha=0) but a brief mention of why this is done would be helpful to educate those who are new to ggplot2 on some of the idiosyncrasies of graphing.

An alternative workaround I have used is to remove outliers from plotting with geom_boxplot --> geom_boxplot(outlier.shape = NA) so that only the geom_jitter function is able to plot outlier points.

dakirsc avatar Jun 07 '22 14:06 dakirsc

Thank you @dakirsc. This is a great suggetion. Semantically, I much prefer the outlier.shape = NA option because it implies that they do not get drawn at all, rather than drawn "invisibly" (fully transparent).

Teebusch avatar Jun 10 '22 09:06 Teebusch