Overview

Welcome! This website contains a collection of graphs created using ggplot2 (and friends!).

Install ggplot2 using the code below:

Code
install.packages("ggplot2")
library(ggplot2)

Or you can install ggplot2 as part of the tidyverse:

Code
install.packages("tidyverse")
library(tidyverse)

The Data

To improve reproducibility, the majority of the graphs are built using the palmerpenguins::penguins data.

…so…many…PENGUINS!

Artwork by @allison_horst

Code
install.packages("palmerpenguins")
library(palmerpenguins)

Some of the graphs use datasets from the fivethirtyeight package.

Code
install.packages("fivethirtyeight")
library(fivethirtyeight)

To view a table of available datasets in the fivethirtyeight package, view the Data Frame Name and Article Title columns in the datasets_master table:

A few of the graphs are built using the ggplot2movies::movies data.

Code
install.packages("ggplot2movies")
library(ggplot2movies)

The Graphs

The gallery follows a Rule of Least Power Principle, in the sense that “a language with a straightforward syntax may be easier to analyze than an otherwise equivalent one with more complex structure.

In other words, assuming the reader has some understanding of R and the tidyverse, the code for each graph is meant to be read and understood without having to run it.

Graph Categories

Graphs have been categorized into the following types:

  • Univariate graphs
  • Amounts
  • Proportions
  • Comparing Distributions
  • Relationships

Some graphs would justifiably belong in more than one category, and wherever this is the case, I’ve tried to include links to other uses in the notes.

Code style & structure

Each graph has, at minimum, the same two sections and four tabs:

  1. Packages and Data
    • Code for installing development version of packages (if necessary) for graphs and data
    • Any steps used to create (i.e., manipulate and prepare) the data for the graph
  2. Code and Graph
    • Code to build the labels and graph layers
      • Graph labels have the labs_ prefix
      • Graph layers have a ggp2_ prefix

PACKAGES:

Install packages.

Code
library(ggplot2)

DATA:

Description of data

Code
df <- tibble::tibble(X = sample(x = 1:100, 10, FALSE),
                     Y = rlnorm(10, 1, 3))

CODE:

Code for creating graph

Code
# labels
labs_graph <- ggplot2::labs(title = "Title", 
                            subtitle = "subtitle", 
                            x = "X", y = "Y")
# layers
ggp2_graph <- ggplot2::ggplot(data = df, 
    mapping = aes(x = X, y = Y)) + 
    ggplot2::geom_blank()
# graph
ggp2_graph + 
    labs_graph

GRAPH:

Code Style:

I’ve attempted to balance brevity and clarity, but with the assumption that its best to err on the latter. I’ve also followed the general principle that if a graph can be easily built using one of ggplot2 ’s geom_* functions, that method is shown first.

Extensions

Below are the graphs requiring additional packages/extensions:

  • Waffle charts

    • ggwaffle package

      Code
      # Waffle Charts
      devtools::install_github("liamgilbey/ggwaffle")
      library(ggwaffle)
  • Pie Charts

    • ggpubr package

      Code
      # Pie Charts 
      devtools::install_github("kassambara/ggpubr")
      library(ggpubr)
  • Mosaic Plots

    • ggmosaic package

      Code
      # Mosaic Charts 
      devtools::install_github("haleyjeppson/ggmosaic")
      library(ggmosaic)
  • Treemaps

    • treemapify package

      Code
      # Treemaps
      devtools::install_github("wilkox/treemapify")
      library(treemapify)
  • Bee-swarm Plots

    • ggbeeswarm package

      Code
      # Bee-swarm Plots
      devtools::install_github("eclarke/ggbeeswarm")
      library(ggbeeswarm)
  • Ridgeline Plots

    • ggridges package

      Code
      # Ridgeline plots 
      devtools::install_github("wilkelab/ggridges")
      library(ggridges)
  • Rain-cloud plots

    • raincloudplots and ggdist packages

      Code
      # Rain-cloud plots 
      remotes::install_github('jorvlan/raincloudplots')
      remotes::install_github('mjskay/ggdist')
      library(raincloudplots)
      library(ggdist)
  • Alluvial charts

    • ggalluvial package

      Code
      # Alluvial charts
      devtools::install_github("corybrunson/ggalluvial")
      library(ggalluvial)
  • Bump charts

    • ggbump package

      Code
      # Bump charts
      devtools::install_github("davidsjoberg/ggbump")
      library(ggbump)
  • Parallel Sets

    • ggforce package

      Code
      # Bump charts
      devtools::install_github("thomasp85/ggforce")
      library(ggforce)
  • Stream Plots

    • ggstream package

      Code
      # Stream plots
      devtools::install_github("davidsjoberg/ggstream")
      library(ggstream)

Theme

The theme used in the graphs is custom and uses combined elements from ggplot2::theme_minimal() and ggplot2::theme_void(). View it here.