Code
install.packages("ggplot2")
library(ggplot2)Welcome! This website contains a collection of graphs created using ggplot2 (and friends!).
Install ggplot2 using the code below:
install.packages("ggplot2")
library(ggplot2)Or you can install ggplot2 as part of the tidyverse:
install.packages("tidyverse")
library(tidyverse)To improve reproducibility, the majority of the graphs are built using the palmerpenguins::penguins data.
…so…many…PENGUINS!
install.packages("palmerpenguins")
library(palmerpenguins)Some of the graphs use datasets from the fivethirtyeight package.
install.packages("fivethirtyeight")
library(fivethirtyeight)A few of the graphs are built using the ggplot2movies::movies data.
install.packages("ggplot2movies")
library(ggplot2movies)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.
Graphs have been categorized into the following types:
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.
Each graph has, at minimum, the same two sections and four tabs:
labs_ prefixggp2_ prefixPACKAGES:
Install packages.
library(ggplot2)DATA:
Description of data
df <- tibble::tibble(X = sample(x = 1:100, 10, FALSE),
Y = rlnorm(10, 1, 3))CODE:
Code for creating graph
# 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_graphGRAPH:
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.
Below are the graphs requiring additional packages/extensions:
Waffle charts
# Waffle Charts
devtools::install_github("liamgilbey/ggwaffle")
library(ggwaffle)Pie Charts
# Pie Charts
devtools::install_github("kassambara/ggpubr")
library(ggpubr)Mosaic Plots
# Mosaic Charts
devtools::install_github("haleyjeppson/ggmosaic")
library(ggmosaic)Treemaps
# Treemaps
devtools::install_github("wilkox/treemapify")
library(treemapify)Bee-swarm Plots
# Bee-swarm Plots
devtools::install_github("eclarke/ggbeeswarm")
library(ggbeeswarm)Ridgeline Plots
# Ridgeline plots
devtools::install_github("wilkelab/ggridges")
library(ggridges)Rain-cloud plots
raincloudplots and ggdist packages
# Rain-cloud plots
remotes::install_github('jorvlan/raincloudplots')
remotes::install_github('mjskay/ggdist')
library(raincloudplots)
library(ggdist)Alluvial charts
# Alluvial charts
devtools::install_github("corybrunson/ggalluvial")
library(ggalluvial)Bump charts
# Bump charts
devtools::install_github("davidsjoberg/ggbump")
library(ggbump)Parallel Sets
# Bump charts
devtools::install_github("thomasp85/ggforce")
library(ggforce)Stream Plots
# Stream plots
devtools::install_github("davidsjoberg/ggstream")
library(ggstream)The theme used in the graphs is custom and uses combined elements from ggplot2::theme_minimal() and ggplot2::theme_void(). View it here.