ABSTRACT

This chapter discusses data visualization using ggplot2. The grammar of graphics is explained with several motivating examples. Histograms, barplots, density plots, and qq plots are presented as visualizations of a single variable, and a data set discussing the Bechdel test is introduced. Next, visualizations of two or more variables are considered, including scatterplots and line graphs. Color and faceting are also introduced in the context of visualizing two or more variables. Data sets include babynames, the full text of Pride and Prejudice, and an electric car charging. Finally, we discuss customizing the visualization. Color scales are discussed in detail. The importance of providing finishing touches via labels and themes is illustrated by producing a chart that examines the result of the Bechdel test over time. Other customization tools presented include annotation and highlighting, with more examples from babynames. The chapter concludes with two vignettes. One vignette discusses choropleth maps, and the other discusses visualizing COVID-19 cases over time.