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
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))
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:
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:
[,2] means “column 2” and
[,1] means “column 1.”