European Energy

Data manipulation, Country flags, Slope graph, Function creation

Published

August 3, 2020

Notable topics: Data manipulation, Country flags, Slope graph, Function creation

Recorded on: 2020-08-03

Timestamps by: Eric Fletcher

View code

Screencast

Timestamps

count
dplyr

Using count to get an overview of scategorical data

pivot_longergather
tidyr

Using pivot_longer and gather to pivot date variables from wide to long

as.integer
base

Using as.integer to change year variable from character to integer class

fct_reorder
forcats

Using fct_reorder to reorder stacked barplot

scale_y_continuouscomma
ggplot2scales

Using scale_y_continuous with labels = comma from scales package to insert a comma every three digits on the y-axis

replace_na
tidyr

Using replace_na and list to replace NA values in country_name column with United Kingdom

fct_lump
forcats

Using fct_lump to lump factor levels together except for the 10 most frequent for each facet panel

reorder_withinscale_y_reordered
tidytext

Using reorder_within with fun = sum and scale_y_reordered to reorder the categories within each facet panel

geom_flag
ggfalgs

Using ggflags package to add country flags | Debugging strategies include 1) minimal reproducible example and 2) binary search

fct_recode
forcats

(Unsuccessfully) Using fct_recode to rename the ISO two-digit identifier for the United Kingdom from the UK to GB

ifelse
base

Using ifelse to replace the ISO two-digit identifier for the United Kingdom from UK to GB & from EL to GR fro Greece | Debugging included

str_to_lower
stringr

Using str_to_lower to convert observations in country column to lower case

geom_pointgeom_linescale_y_log10geom_flag
ggplot2ggflags

Creating a slope graph to show differences in Nuclear production (2106 versus 2018) | Using scale_y_log10 to increase distance between points | Using ggflags for country flags

scale_x_continuous
ggplot2

Using scale_x_continuous with breaks = c(2016, 2018) to show only 2016 and 2018 on x-axis

scale_x_continuousgeom_text
ggplot2

Extend x-axis limits using scale_x_continuous with limits = c(2015, 2019) and geom_text with an ifelse within hjust to alternate labels for the right and left side of slope graph

function
base

Creating a slopegraph function

Summary of screencast