9 Visualizing data: Plotting

 

This chapter covers

  • Preparing data for visualizations
  • Plotting data the tidy way: ggplot2
  • Saving graphics to files

Visualizations of data help both you and people you share your results with gain insight into relationships inherent in the data. When you have many data points (even just a handful), a plot (a graph, a graphic, or some other sort of image) can convey a great deal of information that a table can’t. That’s not to say plots are always the best way to convey information, but when they are, you need tools to generate them easily and effectively with R.

9.1 Data preparation

By now you’ve taken raw data, performed some operations on it (cleaned, sliced, and diced), and are ready to plot it to see what secrets it might be able to tell. The optimum arrangement of the data in terms of joining together pieces of information may not, however, be the optimum arrangement in terms of thinking about reslicing it for visualization.

It’s not uncommon to need to generate another version of a dataset specifically for visualization, but that should be reproducibly derivable from both the original raw data and any subsequent transformations performed. When you have various groups in data, one useful way to include this information in a visualization is to visually separate the groups, by color, shape, linetype, or physical distance. This means the data needs to be in a format that is amenable to such splitting.

9.1.1 Tidy data, revisited

9.1.2 Importance of data types

9.2 ggplot2

9.2.1 General construction

9.2.2 Adding points

9.2.3 Style aesthetics

9.2.4 Adding lines

9.2.5 Adding bars

9.2.6 Other types of plots

9.2.7 Scales

9.2.8 Facetting

9.2.9 Additional options

9.3 Plots as objects

9.4 Saving plots

9.5 Try it yourself

Terminology

Summary

sitemap