Kenya Census

Heatmap, Joining Datasets, ShapeFile, Choropleth Map, rKenyaCensus

Published

January 18, 2021

Notable topics: Heatmap, Joining Datasets, ShapeFile, Choropleth Map, rKenyaCensus

Recorded on: 2021-01-18

Timestamps by: Eric Fletcher

View code

Screencast

Timestamps

str_trim
stringr

Trim whitespace from a string.

fct_reorder
forcats

Reorder factor levels by sorting along another variable by sum.

commascale_x_continuous
scalesggplot2

Label x axis numbers in decimal format (e.g. 0.12, 1,234).

gather
tidyr

Pivot data from wide to long.

str_to_title
stringr

Convert case of a string to title case.

geom_text
ggplot2

Add text labels to the geom_point plot.

geom_hline
ggplot2

Add horizontal reference line to geom_point plot.

commascale_y_continuous
scalesggplot2

Label y axis numbers in percent format.

expand_limits
ggplot2

Expand the plot axis limits by having the y axis begin at 0.

scale_x_log10
ggplot2

Position x axis data on a log10 scale.

gather
tidyr

Pivot data from wide to long.

str_to_title
stringr

Convert case of a string to title case.

fct_reorder
forcats

Reorder factor levels by sorting along another variable by sum.

geom_tile
ggplot2

Create a heatmap.

complete
tidyr

Complete a data frame with missing combinations of data.

theme
ggplot2

Rotate x axis labels 90 degrees.

full_join
dplyr

Join two datasets while including all rows in x or y.

str_replace_all
stringr

Replace matched patterns in a string using str_replace_all with the regular expression ([a-z])([A-Z]) and "\\1 \\2" to separate words that were joined together (e.g. TanaRiver, Tana River).

anti_join
dplyr

Join two datasets while returning all rows from x without a match in y.

right_join
dplyr

Join two datasets while including all rows in y.

inner_join
dplyr

Join two datasets while including all rows in x and y.

KenyaCounties_SHP
rKenyaCensus

Import and basic exploration of the rKenyaCensus package shapefiles.

st_as_sfgeom_sf
ggplot2sf

Create a map using the rKenyaCensus shapefile data.

st_simplify
sf

Simplify the shapefile data to make for faster processesing.

left_join
dplyr

Join two datasets while including all rows in x.

ggplotgeom_sftheme_map
ggplot2sf

Create a choropleth map - TROUBLSHOOTING through 41:45.

filtergathermutategroup_bysummarizespreadselect
ggplot2dplyrtidyr

Create a flexible function that generates geom_col plots used for for exploring the many different datasets in the rKenyaCensus package.

fct_lump
forcats

Lump together factor levels into "other".

Summary of screencast.