Adding Jittered Data Points to the Grouped Boxplot

Here we are adding jitter data points into the grouped boxplot using geom_point() method.

Syntax of geom_point(): geom_point(mapping = NULL, data = NULL,  position = “identity”, … )

Arguments:

  • mapping – Set of aesthetic mappings
  • data = dataset
  • position – Position adjustment of points

Adding jittered data points using geom_point( ) function and position_jitterdodge( ) argument

Let’s add jittered data points on the boxplot to visualize the spread of the data with respect to each game.

R




# Adding jittered data points on the boxplot
  
ggplot(data, aes(x = game, y = score, fill = level)) + 
geom_boxplot(outlier.shape = NA)+
geom_point(position = position_jitterdodge(), alpha=0.3)


Output:

Plotting a Grouped Boxplot with jittered points with respect to performance in each game in each year

Let’s add jittered data points on the boxplot using geom_point( ) and facet_wrap( ) functions to compare the performance of scores in each game per year in different facets.

R




# jittered points on boxplots in 3 facets by year
  
ggplot(data, aes(x = level, y = score, fill = game)) + 
geom_boxplot()+
geom_jitter(width = 0.1,alpha = 0.3) +
facet_wrap(~year)


Output:



How to Make Grouped Boxplot with Jittered Data Points in ggplot2 in R

In this article, we will see how to make use of ggplot2 package in R Programming Language to plot grouped boxplots with jittered data points.

Grouped Boxplots help us visualize two or more features/variables in a single plot using the grouping variable in ggplot2. The jittered points are data points that belong to another variable and are plotted on top of the grouped boxplot for a better comparison of the spread of data points of the considered variables. 

Similar Reads

Creating a DataFrame

Here we can use any in-built datasets in R (the list of datasets can be viewed using data( ) command) or even create one. Let’s create a data frame and visualize it....

Plotting Grouped Boxplots

...

Adding Jittered Data Points to the Grouped Boxplot

Here we are going to plot boxplots using geom_boxplot() methods....