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.
{ggbeeswarm}
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
To get started with ggbeeswarm
, you can install it
directly from CRAN using the install.packages
function:
The ggbeeswarm
package makes it easy to create beeswarm
plots using the geom_beeswarm()
function.
Hereβs a basic example:
ggplot(iris, aes(x = Species, y = Sepal.Length, colour=Species)) +
geom_beeswarm() +
theme_minimal() +
scale_color_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
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()
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()
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.
For more beeswarm example, you can check the dedicated section of the R graph gallery.