How do I overlay individual data points in a boxplot in R?

211 views Asked by At

This is my code:

boxplot(PhysData, main="PhysData", col= c("red", "orange", "yellow", "green", "lightblue", "royalblue", "purple", "pink"))) 

It has 8 columns of data (basically 4 sets of 2). But I want to include the individual data points to the boxplot (so I don't want to change anything about the boxplot, just adding all the other data points on top).

I'm working in Rstudio if that changes anything from R. And I'm very beginner so please explain every detail even if you think it's obvious!

I've tried looking at other questions on here about similar things, but I can't find one that explains exactly what I'm trying to do. I don't want random data added (which is what my impression of the jitter function is), but the actual data collected. Also most of what I've found use ggplot() instead of boxplot(). Is there a difference (and with geom_boxplot) and what is it?

1

There are 1 answers

0
Juli On

I would recommend using ggplot::geom_boxplot() instead of base::boxplot().

The jitter function does not add random data but spaces the existing data so you can see single data points without overlay. This article explains the use of geom_boxplot(). Code examples are also given.