Customize dots in beeswarm plots



A beeswarm plot displays individual data points in a way that they don’t overlap, resulting in a swarming effect that resembles a swarm of bees.
In the previous post we saw how to build one with R and the beeswarm package.
In this post, we’ll see how to custom the dots: changing their size, color and shape.

Beeswarm Data to Viz

Packages


For this post, we need to install and load the beeswarm package.

We can install it from CRAN using install.packages("beeswarm"). Then, we can load it:

# install.packages("beeswarm")
library(beeswarm)


Dataset


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:

data(iris)

Change dots color


The package comes with a beeswarm() function, and thanks to its col argument, we can change the color of the dots. Here, we’ll use the blue color.

beeswarm(
  iris$Sepal.Length,
  col="blue"
)

Change dots symbol


The pch argument allows to change the symbol of the dots. Here, we’ll use the 16 symbol since it’s the same as before but filled.

beeswarm(
  iris$Sepal.Length,
  pch=16
)

Change dots size


The cex argument allows to change the size of the dots. Here, we’ll use a 2.5 size (default is 1).

beeswarm(
  iris$Sepal.Length,
  cex=2.5
)

Change dots position


The method argument allows to change the position of the dots. Here are the available options:

In our case, we’ll use the center method:

beeswarm(
  iris$Sepal.Length,
  method="center",
  cex=2 # make the dots bigger
)

Going further


This post explains how to customize the dots in a beeswarm plot.

You might also be interested in how to flip a beeswarm plot or how to create a grouped beeswarm plot.

Related chart types


Violin
Density
Histogram
Boxplot
Ridgeline



Contact

This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message on Twitter, or send an email pasting yan.holtz.data with gmail.com.