11 Chart: Cleveland Dot Plot

This page is a work in progress. We appreciate any input you may have. If you would like to help improve this page, consider contributing to our repo.

11.1 Overview

This section covers how to make Cleveland dot plots. Cleveland dot plots are a great alternative to a simple bar chart, particularly if you have more than a few items. It doesn’t take much for a bar chart to look cluttered. In the same amount of space, many more values can be included in a dot plot, and it’s easier to read as well. R has a built-in base function, dotchart(), but since it’s such an easy graph to draw, doing it “from scratch” in ggplot2 or base allows for more customization.

The code:

11.2 Multiple dots

For this example we’ll use 2010 data on SAT mean scores for a sample of New York City public schools:

Note that School Name is sorted by factor level, which by default is alphabetical. A better choice is to sort by one of the levels of Test. It’s usually best to try sorting on different factor levels and observe the patterns that appear.

To perform the double sort, that is, sorting School Name by Test and then Mean, we use forcats::fct_reorder2(). This function sorts .f (a factor or character vector) by two sorting vectors, .x and .y. For this type of plot, .x is the variable represented by the colored dots and .y is the continuous variable mapped to the y-axis.

Suppose we wish to sort the schools by mean reading score. We can do this by limiting the Test variable to “Reading” when sorting on Mean:

(Many thanks to Zeyu Qiu for the tip on setting .x directly to the factor level, a much better approach than reordering factor levels to conform with fct_reorder2() defaults, as discussed below.)

While this is the go-to method, there may be cases in which it’s easier to specify that you wish to sort by the first or the last factor level of the first sorting variable (Test), without spelling it out.

If a factor level is not specified, fct_reorder2() by default will sort on the last factor level of .x. In this case, “Writing” is the last factor level of Test:

If you desire to sort by the first factor level of .x, “Math” in this case, you’ll need the development version of forcats, which you can install with:

devtools::install_github("tidyverse/forcats")

Change the default sorting function, last2(), to first2():







with