A beeswarm plot or swarmplot is
a type of data visualization that displays individual data points in a
way that they don’t overlap, resulting in a
swarming effect that resembles a swarm of bees.
In
this post, we’ll see how to create a basic beeswarm plot in R using the
ggbeeswarm package.
For this post, we need to install and load the ggbeeswarm package.
We can install it from CRAN using
install.packages("ggbeeswarm")
. Then, we can load it:
Since beeswarm plots are made to
visualize individual data points, we need a dataset
that contains numerical values. Here, we’ll use the iris
dataset, which is a built-in dataset in R.
We can easily load it:
We can easily create a grouped beeswarm plot by
specifying a categorical variable in the aes()
function.
And in order to make the plot more readable, we can
add some color to the points using the
colour
argument.
We can also customize the colors using the
scale_color_manual()
function. And thanks to the
theme_minimal()
function, we can make the plot a bit
more elegant.
This post explains how to create a grouped beeswarm plot with R and the ggbeeswarm package.
You might also be interested in how to customize a beeswarm plot.
👋 After crafting hundreds of R charts over 12 years, I've distilled my top 10 tips and tricks. Receive them via email! One insight per day for the next 10 days! 🔥