African-American History

Network diagram, Wordcloud

Published

June 15, 2020

Notable topics: Network diagram, Wordcloud

Recorded on: 2020-06-15

Timestamps by: Eric Fletcher

View code

Screencast

Timestamps

fct_lump
forcats

Use fct_lump from the forcats package to lump together all the factor levels in ship_name except the n most frequent. Used within filter with ! = "Other" to remove other.

fct_reorder
forcats

use fct_reorder from the forcats package to reorder the ship_name factor levels y sorting along the n_slaves_arrived variable.

geom_vline
ggplot2

Add geom_vline to geom_histogram to annotate the plot with a vertical line indicating the Revolutionary War and the Civil War.

count
dplyr

Use truncated division within count to create a new decade variable equal to 10 * (year_arrival %/% 10))

str_trunc
stringr

Use str_trunc from the stringr package to truncate the titles in each facet panel accounting for the slave ports with really long names.

theme
ggplot2

Another option for accounting for long titles in the facet panels is to use strip.text within theme with element_text(size = 6)

ggraphgeom_edge_linkgeom_node_pointgeom_node_text
ggraph

Use the ggraph package to create a network diagram using port_origin and port_arrival.

arrow
grid

Use arrow from the grid package to add directional arrows to the points in the network diagram.

scale_edge_size_continuous
ggraph

Use scale_width_size_continuous from the ggraph packge to adjust the size of the points in the network diagram.

summarizemean
dplyr

Within summarize use mean(n_slaves_arrived, na.rm = TRUE) * n()) to come up with an estimated total numer of slaves since 49% of the data is missing.

geom_colfacet_wrap
ggplot2

Create a faceted stacked percent barplot (spinogram) showing the percentage of black_free, black_slaves, white, and other for each region.

wordcloudgeom_text_wordcloud
wordcloudggwordcloud

Use the wordcloud package to create a wordcloud with the african_names dataset. David hsa issues with the wordcloud package and opts to use ggwordcloud instead. Also, mentions the worldcloud2 package.

fct_recode
forcats

Use fct_recode from the forcats package to change the factor levels for the gender variable while renaming Man = "Boy" and Woman = "Girl"

reorder_within
tidytext

Use reorder_within from the tidytext package to reorder the geom_col by n within gender variable for each facet panel.

Summary of screencast.