Dot Charts in Base R - dummies

Dot Charts in Base R

Dot charts are yet another way of visualizing data in the following table. Noted graphics honcho William Cleveland believes that people perceive values along a common scale (as in a bar plot) better than they perceive areas (as in a pie graph). So he came up with the dot chart, shown in the figure.

Types and Frequencies of Cars in the Cars93 data frame

 Type Frequency Compact 16 Large 11 Midsize 22 Small 21 Sporty 14 Van 9

Looks a little like an abacus laid on its side, doesn’t it? This is one of those infrequent cases where the independent variable is on the y-axis and the dependent variable is on the x-axis.

The format for the function that creates a dot chart is

> dotchart(x, labels, arg1, arg2 …)

The first two arguments are vectors, and the others are optional arguments for modifying the appearance of the dot chart. The first vector is the vector of values (the frequencies). The second is pretty self-explanatory — in this case, it’s labels for the types of vehicles.

To create the necessary vectors, you turn the table into a data frame:

type.frame <- data.frame(table(Cars93\$Type))

> type.frame

Var1 Freq

1 Compact 16

2 Large 11

3 Midsize 22

4 Small 21

5 Sporty 14

6 Van 9

After you have the data frame, this line produces the dot chart:
> dotchart(type.frame\$Freq,type.frame\$Var1)

The type.frame\$Freq specifies that the Frequency column in the data frame is the x-axis, and type.frame\$Var1 specifies that the Var1 column (which holds the car-types) is the y-axis.

This line works, too:

> dotchart(type.frame[,2],type.frame[,1])

Remember that [,2] means “column 2” and [,1] means “column 1.”