Chapter 6. Basic graphs

 

This chapter covers

  • Bar, box, and dot plots
  • Pie and fan charts
  • Histograms and kernel density plots

Whenever we analyze data, the first thing that we should do is look at it. For each variable, what are the most common values? How much variability is present? Are there any unusual observations? R provides a wealth of functions for visualizing data. In this chapter, we’ll look at graphs that help you understand a single categorical or continuous variable. This topic includes

  • Visualizing the distribution of variable
  • Comparing groups on an outcome variable

In both cases, the variable could be continuous (for example, car mileage as miles per gallon) or categorical (for example, treatment outcome as none, some, or marked). In later chapters, we’ll explore graphs that display bivariate and multivariate relationships among variables.

In the following sections, we’ll explore the use of bar plots, pie charts, fan charts, histograms, kernel density plots, box plots, violin plots, and dot plots. Some of these may be familiar to you, whereas others (such as fan plots or violin plots) may be new to you. Our goal, as always, is to understand your data better and to communicate this understanding to others.

Let’s start with bar plots.

6.1. Bar plots

Bar plots display the distribution (frequencies) of a categorical variable through vertical or horizontal bars. In its simplest form, the format of the barplot() function is

barplot(height)

where height is a vector or matrix.

6.2. Pie charts

6.3. Histograms

6.4. Kernel density plots

6.5. Box plots

6.6. Dot plots

6.7. Summary

sitemap