Skip to content

Instantly share code, notes, and snippets.

@sharlagelfand
Created March 30, 2020 15:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharlagelfand/09cfdfc6fa0311e09eb6585f42d07bdd to your computer and use it in GitHub Desktop.
Save sharlagelfand/09cfdfc6fa0311e09eb6585f42d07bdd to your computer and use it in GitHub Desktop.
library(ggplot2)
library(dplyr)
library(tidytext)
nintendo <- tribble(
~console, ~sales_type, ~sales_million,
"Nintendo Switch", "Hardware", 52.48,
"Nintendo Switch", "Software", 310.65,
"Nintendo 3DS", "Hardware", 75.71,
"Nintendo 3DS", "Software", 382.22,
"Wii U", "Hardware", 13.56,
"Wii U", "Software", 103.01,
"Wii", "Hardware", 101.63,
"Wii", "Software", 921.41,
"Nintendo DS", "Hardware", 154.02,
"Nintendo DS", "Software", 948.69,
"Game Boy Advance", "Hardware", 81.51,
"Game Boy Advance", "Software", 377.42,
"Game Boy", "Hardware", 118.69,
"Game Boy", "Software", 501.11,
"Nintendo GameCube", "Hardware", 21.74,
"Nintendo GameCube", "Software", 208.57,
"Nintendo 64", "Hardware", 32.93,
"Nintendo 64", "Software", 224.97,
"SNES", "Hardware", 49.10,
"SNES", "Software", 379.06,
"NES", "Hardware", 61.91,
"NES", "Software", 500.01
)
light_purple <- "#B7A0CD"
dark_purple <- "#5A5475"
yellow <- "#E9C062"
mint <- "#C0FFDE"
pink <- "#E3837D"
light_pink <- "#F5B6D0"
white <- "#FFFFFF"
blue <- "#96CBFE"
theme_fairyfloss <- function(base_size = 16) {
theme_grey(base_size = base_size, base_family = "Courier") +
theme(
plot.background = element_rect(fill = dark_purple, colour = light_purple),
panel.background = element_rect(fill = light_purple),
panel.grid.major = element_line(colour = blue),
panel.grid.minor = element_blank(),
axis.text = element_text(colour = yellow),
axis.title = element_text(colour = mint),
plot.title = element_text(colour = pink, hjust = 0.5),
plot.subtitle = element_text(colour = pink, hjust = 0.5),
legend.background = element_rect(fill = NA, colour = light_purple),
legend.title = element_text(colour = light_pink),
legend.text = element_text(colour = white),
legend.key = element_rect(fill = NA),
strip.background = element_rect(fill = light_pink),
strip.text = element_text(colour = white)
)
}
ggplot(nintendo, aes(x = sales_million, y = reorder_within(console, sales_million, sales_type))) +
geom_col(fill = dark_purple, alpha = 0.75) +
scale_y_reordered() +
facet_wrap(vars(sales_type), ncol = 2, scales = "free") +
labs(x = "Sales (millions)", y = "",
title = "Nintendo console sales",
subtitle = "As of December 31, 2019") +
theme_fairyfloss()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment