Consider the following data set for this tutorial, where the variable x
is a numeric variable drawn from an exponential distribution and group
is a categorical variable with groups.
Adding points (strip charts) to a base R box plot can be achieved making use of the stripchart
function. You need to pass the data you used to create your box plot, set the "jitter"
method to add random noise over the data points, avoiding overplotting, set the desired aesthetics arguments such as pch
or col
and add = TRUE
so the points are added over the previous plot. Recall that box plots are vertical by default, so you will need to set vertical = TRUE
.
Vertical box plot with points
Horizontal box plot with points
In order to add the points when working with a box plot by group you need to pass the same formula you used to create the box plot to the stripchart
function. Recall that box plots are vertical by default, but stripcharts are not.
Vertical box plot by group with points
Horizontal box plot by group with points
See also