Coder Social home page Coder Social logo

ggpirate's Introduction

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))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.