10 Doing more with ggplot2

 

This chapter covers

  • Creating correlation plots, dot plots, and lollipop charts
  • Modifying ggplot2 labels through transformations and concatenations
  • Enhancing ggplot2 visualizations with legends, annotations, and shapes
  • Changing ggplot2 colors by groups
  • Revealing Simpson’s Paradox

Our purpose in this chapter is to quantify and visualize the relationship in the NBA between team payrolls and team accomplishments. Along the way, we’ll demonstrate ways to go above and beyond with the ggplot2 graphics package—by experimenting with unconventional types of plots; by transforming and augmenting axis labels; by adding legends, annotations, and shapes; and by segmenting groups by color. When we visualize data instead of relegating it to rows and columns in a table, we accelerate our capacity to learn from it and our ability to act on it. We readily see correlations between variables, trends over time, unusual patterns, frequencies, distributions, and outliers that are near impossible to spot in a spreadsheet or some other like output. Sometimes small touches can have major effects on your visual content.

10.1 Loading packages

10.2 Importing and viewing data

10.3 Salaries and salary cap analysis

10.4 Analysis

10.4.1 Plotting and computing correlations between team payrolls and regular season wins

10.4.2 Payrolls versus end-of-season results

10.4.3 Payroll comparisons

Summary