Skip to content

josesho/ggbeeswarm

 
 

Repository files navigation

Beeswarm-style plots with ggplot2

Introduction

Beeswarm plots (aka column scatter plots or violin scatter plots) are a way of plotting points that would ordinarily overlap so that they fall next to each other instead. In addition to reducing overplotting, it helps visualize the density of the data at each point (similar to a violin plot), while still showing each data point individually.

ggbeeswarm provides two different methods to create beeswarm-style plots using ggplot2. It does this by adding two new ggplot Geom objects:

See the examples below.

Installation

# And until this package is on CRAN:
devtools::install_github("eclarke/ggbeeswarm")

Examples

geom_quasirandom()

Using geom_quasirandom:

set.seed(12345)
library(ggplot2)
library(ggbeeswarm)
qplot(Species, Sepal.Length, data=iris)+ geom_quasirandom()

plot of chunk ggplot2-examples

qplot(class, hwy, data=mpg, geom="quasirandom")

plot of chunk ggplot2-examples

# With categorical y-axis
qplot(hwy, class, data=mpg, geom='quasirandom')

plot of chunk ggplot2-examples

# Some groups may have only a few points. Use `varwidth=TRUE` to adjust width dynamically.
qplot(class, hwy, data=mpg) + geom_quasirandom(varwidth = TRUE)

plot of chunk ggplot2-examples

geom_beeswarm()

Using geom_beeswarm:

qplot(Species, Sepal.Length, data=iris) + geom_beeswarm()

plot of chunk ggplot2-beeswarm

qplot(class, hwy, data=mpg, geom='beeswarm')

plot of chunk ggplot2-beeswarm

# With categorical y-axis
qplot(hwy, class, data=mpg, geom='beeswarm')

plot of chunk ggplot2-beeswarm

# ggplot doesn't pass any information about the actual device size of the points
# to the underlying layout code, so it's important to manually adjust the `cex` 
# parameter for best results
qplot(class, hwy, data=mpg)+ geom_beeswarm(cex=5)

plot of chunk ggplot2-beeswarm

qplot(Species, Sepal.Length, data=iris) +geom_beeswarm(cex=4,priority='density')

plot of chunk ggplot2-beeswarm


Authors: Erik Clarke and Scott Sherrill-Mix

About

Provides methods for beeswarm plots in ggplot2

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • R 92.8%
  • Makefile 7.2%