A solution is provided for each exercise in the book. Do not look at the solution until you have made a serious effort to solve the exercise! For many problems, there will be several possible solutions in R. If you come up with a solution different from the one provided, try to see if the two solutions are equivalent—do you get the same answer? Why or why not?
Solutions provided in the chapter.
attach(mtcars) stripchart(mpg ~ cyl, method = "jitter")
This helps to separate the cars a bit. Now we can see how many cars are in each group.
Not surprisingly, cars with fewer cylinders get better gas mileage.
install.packages("plotrix", dependencies=TRUE) library(plotrix) attach(trees) dotplot.mtb(Volume)
A type of jittering is automatic. Even so, some values that are very close still run together. One way to deal with this is to make the plot character smaller:
dotplot.mtb(Volume, pch = 20) # or dotplot.mtb(Volume, pch = ".") # too small! dotplot.mtb(Volume, pch = "/") # Hmm... detach(trees)
dotchart(USArrests$Murder, labels = row.names(USArrests))
The state names are so big, they overwrite and become illegible!
load("Nimrod.rda") # .rda shows it was saved as an R data frame dotchart(Nimrod$time)
dotchart(Nimrod$time, labels = Nimrod$performer, cex = .5)
Nimrod2 = Nimrod[order(Nimrod$time),] dotchart(Nimrod2$time, labels = Nimrod2$performer, ...