Skip to main content

Unit 2: Into the Tidyverse

This unit introduces the tidyverse, a family of R packages that share one way of working with data. Using a year of flights from New York’s three airports (the nycflights13 data), you learn the dplyr verbs that filter, sort, select, change, and summarize a data frame, chained together with the pipe. The unit ends by turning those tables into graphs with ggplot2.

Chapter 6: Into the Tidyverse: glimpse, filter, and the Pipe

This chapter introduces the tidyverse and the data science workflow it is built around. You look at a data frame with glimpse(), keep the rows you want with filter(), and chain steps together with the pipe, |>. It also explains missing values (NA) and how they affect filtering.

Chapter 7: Into the Tidyverse: arrange, distinct, select, and mutate

dplyr verbs work on either rows or columns. This chapter sorts rows with arrange(), finds unique values with distinct(), keeps the columns you need with select(), and calculates new columns with mutate(). Sorting a new column turns out to be a quick way to spot outliers worth checking.

Chapter 8: Into the Tidyverse: summarize, group_by, and drop_na

summarize() collapses many rows into summary statistics, and group_by() makes it give one answer for each group, such as each month or each airline. The chapter compares two ways of handling missing values, na.rm = TRUE and drop_na(), and shows why the average of averages can mislead and how a weighted average fixes it.

Chapter 9: Into the Tidyverse: Graphs with ggplot2

ggplot2 builds graphs from the grammar of graphics: data, aesthetics that map columns to visual properties, and geoms that draw the marks, added in layers with +. This chapter makes scatterplots, bar charts, and boxplots, explains the difference between setting and mapping an aesthetic, splits plots into small multiples with facets, and finishes plots with colors, labels, themes, and ggsave().