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_
prefixCode 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
::install_github("liamgilbey/ggwaffle")
devtoolslibrary(ggwaffle)
Pie Charts
# Pie Charts
::install_github("kassambara/ggpubr")
devtoolslibrary(ggpubr)
Mosaic Plots
# Mosaic Charts
::install_github("haleyjeppson/ggmosaic")
devtoolslibrary(ggmosaic)
Treemaps
# Treemaps
::install_github("wilkox/treemapify")
devtoolslibrary(treemapify)
Bee-swarm Plots
# Bee-swarm Plots
::install_github("eclarke/ggbeeswarm")
devtoolslibrary(ggbeeswarm)
Ridgeline Plots
# Ridgeline plots
::install_github("wilkelab/ggridges")
devtoolslibrary(ggridges)
Rain-cloud plots
raincloudplots
and ggdist
packages
# Rain-cloud plots
::install_github('jorvlan/raincloudplots')
remotes::install_github('mjskay/ggdist')
remoteslibrary(raincloudplots)
library(ggdist)
Alluvial charts
# Alluvial charts
::install_github("corybrunson/ggalluvial")
devtoolslibrary(ggalluvial)
Bump charts
# Bump charts
::install_github("davidsjoberg/ggbump")
devtoolslibrary(ggbump)
Parallel Sets
# Bump charts
::install_github("thomasp85/ggforce")
devtoolslibrary(ggforce)
Stream Plots
# Stream plots
::install_github("davidsjoberg/ggstream")
devtoolslibrary(ggstream)
The theme used in the graphs is custom and uses combined elements from ggplot2::theme_minimal()
and ggplot2::theme_void()
. View it here.