Database Reference
In-Depth Information
Dotchart and Barplot
Dotchart and barplot from the previous section can visualize multiple variables.
Both of them use color as an additional dimension for visualizing the data.
For the same mtcars dataset, Figure 3.14 shows a dotchart that groups vehicle
cylinders at the y-axis and uses colors to distinguish different cylinders. The
vehicles are sorted according to their MPG values. The code to generate Figure 3.14
is shown next.
# sort by mpg
cars <- mtcars[order(mtcars$mpg),]
# grouping variable must be a factor
cars$cyl <- factor(cars$cyl)
cars$color[cars$cyl==4] <- "red"
cars$color[cars$cyl==6] <- "blue"
cars$color[cars$cyl==8] <- "darkgreen"
dotchart(cars$mpg, labels=row.names(cars), cex=.7, groups=
cars$cyl,
main="Miles Per Gallon (MPG) of Car Models\nGrouped by
Cylinder",
xlab="Miles Per Gallon", color=cars$color, gcolor="black")
Search WWH ::




Custom Search