Adding Bernie Sanders to ggplot2

Package

ggbernie

Author

R CODER

ggbernie package

ggbernie packages includes a ggplot geom named geom_bernie which allows adding Bernie Sanders into R plots. There are seven different images available to add: "sitting", "stand", "head", "young", "arms", "eyebrows" and "asking", which can be selected with bernie argument.

Bernie sitting

# install.packages("remotes")
# remotes::install_github("R-CoderDotCom/ggbernie")
library(ggbernie)

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

ggplot(mtcars, aes(mpg, wt)) +
  geom_bernie(bernie = "sitting")

Bernie sitting

Bernie standing

# install.packages("remotes")
# remotes::install_github("R-CoderDotCom/ggbernie")
library(ggbernie)

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

ggplot(mtcars, aes(mpg, wt)) +
  geom_bernie(bernie = "stand")

Bernie stand

Bernie head

# install.packages("remotes")
# remotes::install_github("R-CoderDotCom/ggbernie")
library(ggbernie)

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

ggplot(mtcars, aes(mpg, wt)) +
  geom_bernie(bernie = "head")

Bernie head

Young Bernie

# install.packages("remotes")
# remotes::install_github("R-CoderDotCom/ggbernie")
library(ggbernie)

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

ggplot(mtcars, aes(mpg, wt)) +
  geom_bernie(bernie = "young")

Bernie young

Bernie arms

# install.packages("remotes")
# remotes::install_github("R-CoderDotCom/ggbernie")
library(ggbernie)

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

ggplot(mtcars, aes(mpg, wt)) +
  geom_bernie(bernie = "arms")

Bernie arms

Bernie eyebrows

# install.packages("remotes")
# remotes::install_github("R-CoderDotCom/ggbernie")
library(ggbernie)

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

ggplot(mtcars, aes(mpg, wt)) +
  geom_bernie(bernie = "eyebrows")

Bernie eyebrows

Bernie asking

# install.packages("remotes")
# remotes::install_github("R-CoderDotCom/ggbernie")
library(ggbernie)

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

ggplot(mtcars, aes(mpg, wt)) +
  geom_bernie(bernie = "asking")

Bernie asking

Community memes

The Rstats Twitter community made some amazing memes with ggbernie. Below you can see how to create one of this BerniePlots.

Bernie Sanders meme

# install.packages("Ecdat")
library(Ecdat)
# install.packages("tidyverse")
library(tidyverse)
# remotes::install_github("R-CoderDotCom/ggbernie")
library(ggbernie)
# install.packages("gganimate")
library(gganimate)

# DAta
data(incomeInequality)

# Data frame
dat <- incomeInequality %>%
       select(Year, P99, median) %>% 
  rename(income_median = median,
         income_99percent = P99) %>% 
  pivot_longer(cols = starts_with("income"),
               names_to = "income",
               names_prefix = "income_")

# Plot
ggplot(dat, aes(x = Year,
                y = value,
                group = income,
                color = income)) +
  geom_line(size = 2) +
  viridis::scale_color_viridis(discrete = TRUE) +
  ggtitle("Jimmy, make a meme about income inequality") +
  scale_y_continuous(labels = scales::dollar_format()) +
  theme_bw() + 
  geom_bernie(bernie = "sitting") +
  ylab("That's a lot of pastrami sandwiches!") +
  transition_reveal(Year)
ggplot2

Elegant Graphics for Data Analysis

Buy on Amazon
Data Sketches

A journey of imagination, exploration, and beautiful data visualizations

Buy on Amazon
Storytelling with Data

A Data Visualization Guide for Business Professionals

Buy on Amazon

See also