Create beeswarm plot with ggbeeswarm


The ggbeeswarm package in R is an extension of the ggplot2 package, designed to simplify the process of creating beeswarm plots. This post showcases the key features of ggbeeswarm and provides a set of graph examples using the package.

Documentation

{ggbeeswarm}

Quick start


The ggbeeswarm package in R is an extension of the ggplot2 package, designed to simplify the process of creating beeswarm plots.

It offers 2 main functions to create beeswarm plots: geom_quasirandom() and geom_beeswarm().

✍️ author β†’ Erik Clarke

πŸ“˜ documentation β†’ github

⭐️ more than 500 stars on github

Installation


To get started with ggbeeswarm, you can install it directly from CRAN using the install.packages function:

install.packages("ggbeeswarm")

Basic usage


The ggbeeswarm package makes it easy to create beeswarm plots using the geom_beeswarm() function.

Here’s a basic example:

library(ggplot2)
library(ggbeeswarm)

ggplot(iris, aes(x = Species, y = Sepal.Length, colour=Species)) +
  geom_beeswarm()

Key features


β†’ Customizing color and theme

ggplot(iris, aes(x = Species, y = Sepal.Length, colour=Species)) +
  geom_beeswarm() +
  theme_minimal() +
  scale_color_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))


β†’ Changing dots size

Thanks to the size argument, you can change the size of the dots. Here is an example with size=3:

ggplot(iris, aes(x = Species, y = Sepal.Length, colour=Species)) +
  geom_beeswarm(size=3) +
  theme_minimal()


β†’ Changing dots position

There are multiple methods to position the dots. Here is an example with method = "center":

ggplot(iris, aes(x = Species, y = Sepal.Length, colour=Species)) +
  geom_beeswarm(method = "center") +
  theme_minimal()


β†’ Splitting the plot

You can split the plot by a variable using the split argument.

With side=1L it will be on the right side of the axis and with side=-1L it will be on the left side of the axis.

ggplot(iris, aes(x = Species, y = Sepal.Length, colour=Species)) +
  geom_beeswarm(side = -1L) +
  theme_minimal()




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.

Github Twitter