pirate plots for ggplot2
Branch: master
Clone or download
Latest commit 1009855 Sep 10, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R aesthetic mapping tweaks Sep 10, 2018
man add arguments for specifying layer parameters #3 Apr 6, 2018
.Rbuildignore README from Rmd Oct 3, 2017
.gitignore more info in geom_pirate docs Sep 26, 2017
DESCRIPTION add arguments for specifying layer parameters #3 Apr 6, 2018
NAMESPACE implement geom_pirate based on GeomPoint, GeomCol, GeomCrossbar, and … Sep 26, 2017
README-colour-1.png aesthetic mapping tweaks Sep 10, 2018
README-dodge-1.png aesthetic mapping tweaks Sep 10, 2018
README-facets-1.png aesthetic mapping tweaks Sep 10, 2018
README-layers-1.png aesthetic mapping tweaks Sep 10, 2018
README-params-1.png aesthetic mapping tweaks Sep 10, 2018
README.Rmd aesthetic mapping tweaks Sep 10, 2018
README.md
ggpirate.Rproj

README.md

ggpirate

A pirate plot is a way of displaying data where a continuous dependent variable is a function of a categorical independent variable, in a more informative way than the traditional barplot. geom_pirate() plots the raw data as points (using ggplot2::geom_jitter()), along with layers showing descriptive and inferential statistics -- bars indicating means (using ggplot2::geom_col()), horizontal line indicating means (using ggplot2::geom_crossbar()), boxes indicating 95% confidence intervals assuming a normal sampling distribution (using ggplot2::geom_tile()), and violins indicating the density (using ggplot2::geom_violin()).

Installation

You can install ggpirate from github with:

# install.packages("devtools")
devtools::install_github("mikabr/ggpirate")

Examples

library(ggpirate)
theme_set(theme_bw())

Colour pirate plot:

ggplot(mpg, aes(x = class, y = cty)) +
  geom_pirate(aes(colour = class, fill = class))

Each of the layers can be turned off, e.g. for just means and confidence intervals:

ggplot(mpg, aes(x = class, y = cty)) +
  geom_pirate(aes(colour = class),
              points = FALSE, bars = FALSE, violins = FALSE)

Colour can be mapped to a different variable than the x axis, resulting in dodged subgroups:

mpg2 <- dplyr::mutate(mpg, drv = factor(drv))

ggplot(mpg2, aes(x = class, y = cty)) +
  geom_pirate(aes(colour = drv, fill = drv), show.legend = TRUE)

And it plays well with facetting:

mpg_gather <- tidyr::gather(mpg, type, mileage, cty, hwy)

ggplot(mpg_gather, aes(x = class, y = mileage)) +
  facet_wrap(~type) +
  geom_pirate(aes(colour = class, fill = class))

Finally, the parameters passed to any of the layers can be adjusted, e.g.:

ggplot(mpg, aes(x = class, y = cty)) +
  geom_pirate(aes(colour = class), bars = FALSE,
              points_params = list(shape = 19, alpha = 0.2),
              lines_params = list(size = 0.8))