Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###################################################################################################
- # Big Mac Index - Change in price of the McDonald's Big Mac burger from 2000 to 2020
- # Created by: reddit.com/user/brianhaas19
- # Link to data
- # https://github.com/rfordatascience/tidytuesday/blob/master/data/2020/2020-12-22
- # Setup
- library(tidyverse)
- library(scales)
- library(patchwork)
- theme_set(theme_bw())
- # Load data
- big_mac <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-12-22/big-mac.csv')
- df <- big_mac # generic name
- # Clean data
- ### Filter for countries with mostly complete data:
- complete_data <- df %>%
- count(name) %>%
- filter(n >= 19) %>% # this leaves 42 countries
- .$name
- df <- df %>%
- filter(name %in% complete_data)
- # Visualize
- # Suggested parameters for R notebook: fig.height=12, fig.width=9
- ### Colors
- colors <- c("bun" = "#F7C064",
- "burger" = "#7A4E3D",
- "lettuce" = "#A0C03A",
- "sauce" = "#F5DE92",
- "cheese" = "#F9E239",
- "sesame" = "#F9F3D9",
- "red" = "#DF4458")
- # Ref: https://images.app.goo.gl/3iAvxZfQ9r75CCVz6
- ### Plot
- p1 <- df %>%
- mutate(name2 = name) %>% # use a duplicate column to allow 'highlighting' within each facet
- ggplot(aes(date, dollar_price)) +
- geom_line(data = df,
- aes(group = name),
- color = colors["sauce"],
- alpha = 0.7) +
- geom_line(color = colors["burger"]) +
- facet_wrap(~name2, nrow = 7) +
- labs(x = "Date", y = "Price in USD",
- title = expression(paste(bold("Big Mac Index"), " - Change in price of the McDonald's Big Mac burger from 2000 to 2020")),
- subtitle = "The price in USD is calculated by converting from local currency to US dollars using the appropriate exchange rate.",
- caption = expression(paste("Created by: ", italic("reddit.com/user/brianhaas19"), "\tData source: ", italic("https://github.com/rfordatascience/tidytuesday/blob/master/data/2020/2020-12-22")))) +
- scale_x_continuous(breaks = seq(min(df$date), max(df$date), length.out = 5),
- labels = date_format("'%y")) +
- scale_y_continuous(breaks = seq(2.5, 7.5, 2.5), labels = dollar) +
- theme(plot.title = element_text(color = colors["burger"]),
- plot.subtitle = element_text(color = colors["burger"]),
- plot.caption = element_text(color = colors["burger"], hjust = 0),
- plot.background = element_rect(fill = colors["bun"]),
- panel.background = element_rect(fill = colors["bun"]),
- panel.grid.major = element_line(color = colors["lettuce"], size = 0.25, linetype = "dashed"),
- panel.grid.minor = element_blank(),
- axis.title = element_text(color = colors["burger"]),
- axis.text = element_text(color = colors["burger"]),
- strip.background = element_rect(fill = colors["red"]),
- strip.text = element_text(color = colors["cheese"]))
- p1
- ### Uncomment to save to disk:
- # ggsave(plot = p1,
- # filename = str_c(getwd(), "/big_mac_index.png"),
- # height = 12, width = 9)
- ###################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement