Big Mac Index

Data manipulation, Pairwise correlation

Published

December 21, 2020

Notable topics: Data manipulation, Pairwise correlation

Recorded on: 2020-12-21

Timestamps by: Eric Fletcher

View code

Screencast

Timestamps

add_count
dplyr

Use the add_count function from the dplyr package with name = "country_total" to count the number of observations by group in the name variable.

filtermax
dplyrbase

Use filter from the dplyr package with country_total == max(country_total) to filter the data for countries where every data point is provided.

rename
dplyr

Use the rename function from the dplyr package to rename the name variable to country_name.

theme
ggplot2

Use theme(legend.position = "none") to hide the legend generated by the geom_line plot.

expand_limits
ggplot2

Use the expand_limits function from the ggplot2 package with y = 0 so that each facet panel has a y-axis that starts at the same point, in this case 0.

fct_reorder
forcats

Reorder facet panels using the fct_reorder from the forcats package with a function passed in to the .fun argument to calculate the ratio between max and min values in the local_price variable. At 12:00, David changes from using max and min to last and first to calculate the Big Mac inflation rate.

scale_x_log10
ggplot2

Use scale_x_log10 from the ggplot2 package to change the breaks for the x-axis while also applying a log10 tranformation.

geom_textpaste0
ggplot2base

Use geom_text from the from the ggplot2 with paste0 package to add labels to each bar in the plot indicating how many time X the price of a Big Mac increased from 2000 to 2020.

geom_line
ggplot2

Add two lines to a plot using 2 geom_line with color = argument and y= argument to distinguish between the two lines.

geom_hline
ggplot2

Use geom_hline from the ggplot2 package to add horizontal reference line to each facet panel.

theme
ggplot2

Use theme from the ggplot2 package with axis.text.x = element_text(angle = 90, hjust = 1) to rmake the x-axis labels horizontal in order to avoid overcrowding.

geom_textgeom_text_repel
ggplot2ggrepel

Use geom_text to add country names to each point in geom_point plot. David then opts to use geom_text_repel from the ggrepel package instead to avoid overcrowding.

geom_smooth
ggplot2

Use geom_smooth from the ggplot2 package with lm smoothing method to help show the linear trend when comparing gdp_dollar to usd_raw.

transition_manualtransition_time
gganimate

Use the gganimate package to animate the GDP per capital versus adjusted big mac index relative to USD over time.

str_to_upperstr_remove
stringr

Use str_to_upper and str_remove to remove _adjusted from base_currency while uppercasing the characters that remain.

pairwise_cor
widyr

Use pairwise_cor from the widyr package to perform pairwise correlation to figure out which countries Big Mac prices tend to move together over time.

Screencast summary.