ggbeeswarm

Column scatter / beeswarm-style plots in ggplot2

https://github.com/eclarke/ggbeeswarm

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 14 committers (14.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.5%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Column scatter / beeswarm-style plots in ggplot2

Basic Info
  • Host: GitHub
  • Owner: eclarke
  • License: gpl-3.0
  • Language: R
  • Default Branch: main
  • Homepage:
  • Size: 18.9 MB
Statistics
  • Stars: 551
  • Watchers: 10
  • Forks: 32
  • Open Issues: 13
  • Releases: 8
Created over 11 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License

README.Rmd

---
title: "Beeswarm-style plots with ggplot2"
output: github_document
---
```{r setup, echo=FALSE, message=FALSE}
knitr::opts_chunk$set(
  fig.retina=2,
  fig.width=6,
  fig.height=4
)
```

[![Build Status](https://travis-ci.org/eclarke/ggbeeswarm.svg?branch=master)](https://travis-ci.org/eclarke/ggbeeswarm)
[![CRAN status](https://www.r-pkg.org/badges/version/ggbeeswarm)](https://cran.r-project.org/package=ggbeeswarm)

## 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](http://ggplot2.org). It does this by adding two new ggplot geom objects:

- `geom_quasirandom`: Uses a [van der Corput sequence](http://en.wikipedia.org/wiki/Van_der_Corput_sequence) or Tukey texturing (Tukey and Tukey "Strips displaying empirical distributions: I. textured dot strips") to space the dots to avoid overplotting. This uses [sherrillmix/vipor](https://github.com/sherrillmix/vipor).

- `geom_beeswarm`: Uses the [beeswarm](https://cran.r-project.org/web/packages/beeswarm/index.html) library to do point-size based offset. 

Features: 

- Can handle categorical variables on the y-axis (thanks @smsaladi, @koncina)
- Automatically dodges if a grouping variable is categorical and `dodge.width` is specified (thanks @josesho)

See the examples below.


## Installation

This package is on CRAN so install should be a simple:
```{r, eval=FALSE}
install.packages('ggbeeswarm')
```

If you want the development version from GitHub, you can do:

```{r, eval=FALSE}
devtools::install_github("eclarke/ggbeeswarm")
```

## Examples
Here is a comparison between `geom_jitter` and `geom_quasirandom` on the `iris` dataset:
```{r ggplot2-compare}
set.seed(12345)
library(ggplot2)
library(ggbeeswarm)
#compare to jitter
ggplot(iris,aes(Species, Sepal.Length)) + geom_jitter()
ggplot(iris,aes(Species, Sepal.Length)) + geom_quasirandom()
```

### geom_quasirandom()

Using `geom_quasirandom`:
```{r ggplot2-examples}

#default geom_quasirandom
ggplot(mpg,aes(class, hwy)) + geom_quasirandom()

# With categorical y-axis
ggplot(mpg,aes(hwy, class)) + geom_quasirandom()

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

# Automatic dodging
sub_mpg <- mpg[mpg$class %in% c("midsize", "pickup", "suv"),]
ggplot(sub_mpg, aes(class, displ, color=factor(cyl))) + geom_quasirandom(dodge.width=1)
```

#### Alternative methods
`geom_quasirandom` can also use several other methods to distribute points. For example:
```{r ggplot2-methods,tidy=TRUE}
ggplot(iris,aes(Species, Sepal.Length)) + geom_quasirandom(method='tukey') + ggtitle('Tukey texture')
ggplot(iris,aes(Species, Sepal.Length)) + geom_quasirandom(method='tukeyDense') + ggtitle('Tukey + density')
ggplot(iris,aes(Species, Sepal.Length)) + geom_quasirandom(method='frowney') + ggtitle('Banded frowns')
ggplot(iris,aes(Species, Sepal.Length)) + geom_quasirandom(method='smiley') + ggtitle('Banded smiles')
ggplot(iris,aes(Species, Sepal.Length)) + geom_quasirandom(method='pseudorandom') + ggtitle('Jittered density')
ggplot(iris,aes(Species, Sepal.Length)) + geom_beeswarm() + ggtitle('Beeswarm')
```

### geom_beeswarm()

Using `geom_beeswarm`:
```{r ggplot2-beeswarm}

ggplot(iris,aes(Species, Sepal.Length)) + geom_beeswarm()
ggplot(iris,aes(Species, Sepal.Length)) + geom_beeswarm(side = 1L)
ggplot(mpg,aes(class, hwy)) + geom_beeswarm(size=.5)
# With categorical y-axis
ggplot(mpg,aes(hwy, class)) + geom_beeswarm(size=.5)
# Also watch out for points escaping from the plot with geom_beeswarm
ggplot(mpg,aes(hwy, class)) + geom_beeswarm(size=.5) + scale_y_discrete(expand=expansion(add=c(0.5,1)))

ggplot(mpg,aes(class, hwy)) + geom_beeswarm(size=1.1)


# With automatic dodging
ggplot(sub_mpg, aes(class, displ, color=factor(cyl))) + geom_beeswarm(dodge.width=0.5)
```

#### Alternative methods

```{r ggplot2-beeswarm-alt}
df <- data.frame(
  x = "A",
  y = sample(1:100, 200, replace = TRUE)
)
ggplot(df, aes(x = x, y = y)) + geom_beeswarm(cex = 2.5, method = "swarm") + ggtitle('method = "swarm" (default)')
ggplot(df, aes(x = x, y = y)) + geom_beeswarm(cex = 2.5, method = "compactswarm") + ggtitle('method = "compactswarm"')
ggplot(df, aes(x = x, y = y)) + geom_beeswarm(cex = 2.5, method = "hex") + ggtitle('method = "hex"')
ggplot(df, aes(x = x, y = y)) + geom_beeswarm(cex = 2.5, method = "square") + ggtitle('method = "square"')
ggplot(df, aes(x = x, y = y)) + geom_beeswarm(cex = 2.5, method = "center") + ggtitle('method = "center"')
```

#### Different point distribution priority

```{r ggplot2-priority}
#With different beeswarm point distribution priority
dat<-data.frame(x=rep(1:3,c(20,40,80)))
dat$y<-rnorm(nrow(dat),dat$x)
ggplot(dat,aes(x,y)) + geom_beeswarm(cex=2) + ggtitle('Default (ascending)') + scale_x_continuous(expand=expansion(add=c(0.5,.5)))
ggplot(dat,aes(x,y)) + geom_beeswarm(cex=2,priority='descending') + ggtitle('Descending') + scale_x_continuous(expand=expansion(add=c(0.5,.5)))
ggplot(dat,aes(x,y)) + geom_beeswarm(cex=2,priority='density') + ggtitle('Density') + scale_x_continuous(expand=expansion(add=c(0.5,.5)))
ggplot(dat,aes(x,y)) + geom_beeswarm(cex=2,priority='random') + ggtitle('Random') + scale_x_continuous(expand=expansion(add=c(0.5,.5)))
```

#### Corral runaway points

```{r ggplot2-corral}
set.seed(1995)
df2 <- data.frame(
  y = rnorm(1000),
  id = sample(c("G1", "G2", "G3"), size = 1000, replace = TRUE)
)
p <- ggplot(df2, aes(x = id, y = y, colour = id))

# use corral.width to control corral width
p + geom_beeswarm(cex = 2.5, corral = "none", corral.width = 0.9) + ggtitle('corral = "none" (default)')
p + geom_beeswarm(cex = 2.5, corral = "gutter", corral.width = 0.9) + ggtitle('corral = "gutter"')
p + geom_beeswarm(cex = 2.5, corral = "wrap", corral.width = 0.9) + ggtitle('corral = "wrap"')
p + geom_beeswarm(cex = 2.5, corral = "random", corral.width = 0.9) + ggtitle('corral = "random"')
p + geom_beeswarm(cex = 2.5, corral = "omit", corral.width = 0.9) + ggtitle('corral = "omit"')
```


------
Authors: Erik Clarke, Scott Sherrill-Mix, and Charlotte Dawson

Owner

  • Name: Erik Clarke
  • Login: eclarke
  • Kind: user
  • Location: San Diego, CA
  • Company: Janssen Research & Development

Data scientist in healthcare. Previously at Penn studying genomics and computational biology.

GitHub Events

Total
  • Issues event: 3
  • Watch event: 20
  • Issue comment event: 8
  • Push event: 3
  • Pull request event: 1
  • Fork event: 1
Last Year
  • Issues event: 3
  • Watch event: 20
  • Issue comment event: 8
  • Push event: 3
  • Pull request event: 1
  • Fork event: 1

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 259
  • Total Committers: 14
  • Avg Commits per committer: 18.5
  • Development Distribution Score (DDS): 0.456
Past Year
  • Commits: 26
  • Committers: 3
  • Avg Commits per committer: 8.667
  • Development Distribution Score (DDS): 0.231
Top Committers
Name Email Commits
sherrillmix s****x 141
Charlotte Dawson c****w@o****m 35
Erik Clarke e****e@g****m 27
Erik Clarke e****l@m****u 18
Joses W. Ho j****h@g****m 12
Shyam Saladi s****i@c****u 8
Erik Clarke e****e 8
Erik Clarke e****l@s****l 4
Gregory Jefferis j****s@g****m 1
Shyam Saladi s****i@g****m 1
Bill Denney b****y 1
Erik Clarke e****e@f****m 1
idemockle i****6@y****m 1
Bob Rudis b****b@r****t 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 70
  • Total pull requests: 28
  • Average time to close issues: 8 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 59
  • Total pull request authors: 11
  • Average comments per issue: 2.27
  • Average comments per pull request: 0.96
  • Merged pull requests: 26
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 2
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 2
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • josesho (4)
  • sherrillmix (4)
  • bersbersbers (3)
  • MarekGierlinski (2)
  • smsaladi (2)
  • jbengler (2)
  • thomasdebeus (1)
  • Ari04T (1)
  • eclarke (1)
  • Leprechault (1)
  • AaronRendahl (1)
  • spocks (1)
  • akhst7 (1)
  • hypercompetent (1)
  • TengMCing (1)
Pull Request Authors
  • sherrillmix (9)
  • csdaw (4)
  • smsaladi (4)
  • eclarke (3)
  • krassowski (2)
  • AaronRendahl (2)
  • idemockle (1)
  • hrbrmstr (1)
  • billdenney (1)
  • josesho (1)
  • jefferis (1)
Top Labels
Issue Labels
fixed-in-dev (9) bug (8) enhancement (6) documentation (3) v0.7.2 (1)
Pull Request Labels

Packages

  • Total packages: 3
  • Total downloads:
    • cran 27,717 last-month
  • Total docker downloads: 49,946
  • Total dependent packages: 34
    (may contain duplicates)
  • Total dependent repositories: 115
    (may contain duplicates)
  • Total versions: 12
  • Total maintainers: 1
cran.r-project.org: ggbeeswarm

Categorical Scatter (Violin Point) Plots

  • Versions: 6
  • Dependent Packages: 30
  • Dependent Repositories: 113
  • Downloads: 27,717 Last month
  • Docker Downloads: 49,946
Rankings
Docker downloads count: 0.0%
Stargazers count: 0.7%
Average: 1.8%
Dependent repos count: 2.1%
Dependent packages count: 2.5%
Forks count: 2.7%
Downloads: 2.8%
Maintainers (1)
Last synced: 10 months ago
proxy.golang.org: github.com/eclarke/ggbeeswarm
  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 6.9%
Last synced: 11 months ago
conda-forge.org: r-ggbeeswarm
  • Versions: 1
  • Dependent Packages: 4
  • Dependent Repositories: 2
Rankings
Dependent packages count: 12.5%
Stargazers count: 17.8%
Dependent repos count: 20.2%
Average: 20.6%
Forks count: 31.9%
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.2 depends
  • ggplot2 >= 3.3.0 depends
  • beeswarm * imports
  • vipor * imports
  • gridExtra * suggests