Public Interest::Data Ethics & Practice
Scale functions control the mapping from data to aesthetics and every aesthetic has a default scale.
All scale functions have a common naming scheme: scale
_name of aesthetic_name of scale
scale_y_continuous
scale_color_discrete
scale_fill_manual
Scale functions frequenty use functions from the scales
package.
tidyr
Convert between long and wide data
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)
See the pivot vignette
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 xinner_join()
: keeps observations in both x and y