Data Viz in R: Week 3
To the slack!
Color used to distinguish groups requires a qualitative color scale that is
Color used to representing values or comparative magnitude requires a sequential color scheme that
Color to highlight a group or threshold value requires accent colors that
ggplot expects tidy data, data that is structured such that
pivot_longer
: Convert wide data to long, or move variable values out of the column names and into the cells.
pivot_longer(df, cols = -country, names_to = "year", values_to = "cases")
pivot_wider
: Convert long data to wide, or move variable names out of the cells and into the column names.
pivot_wider(df, id_cols = country, names_from = type, values_from = count)
separate
: Split a single column into multiple columns by separating each cell in the column into a row of cells.
separate(df, col = rate, into = c("cases", "pop"), sep = "/")
unite
: Combine several columns into a single column by uniting their values across rows.
unite(df, col = year, century:year, sep = "")
Joins merge data sets based on key variables. The syntax is always name_join(x, y, by = "key")
Animated visuals created by Garrick Aden-Buie
full_join()
: keeps all observations in x and yleft_join()
: keeps all observations in xright_join()
: keeps all observations in yinner_join()
: keeps observations in both x and yTo the Script!
A ggplot composer that makes it “ridiculously easy” to arrange multiple plots into a single figure!
R Markdown creates dynamic documents by combining markdown (an easy to write plain text format) with embedded R code chunks. When compiled, the code can be evaluated so that the code, its output, and your prose can be included in the final document to make reports reproducible.
R Markdown files contain
Additional Resources