Skip to Main Content
Graphing Data with R
book

Graphing Data with R

by John Jay Hilfiger
October 2015
Beginner to intermediate content levelBeginner to intermediate
250 pages
6h 26m
English
O'Reilly Media, Inc.
Content preview from Graphing Data with R

Appendix F. Solutions to Chapter Exercises

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?

Exercises 1-1 Through 1-4

Solutions provided in the chapter.

Exercise 3-1

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.

Exercise 3-2

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)

Exercise 4-1

dotchart(USArrests$Murder, labels = row.names(USArrests))

The state names are so big, they overwrite and become illegible!

Exercise 4-2

load("Nimrod.rda") # .rda shows it was saved as an R data frame
dotchart(Nimrod$time)

Good!

dotchart(Nimrod$time, labels = Nimrod$performer, cex = .5)

Better!

 Nimrod2 = Nimrod[order(Nimrod$time),] dotchart(Nimrod2$time, labels = Nimrod2$performer, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

A Course in Statistics with R

A Course in Statistics with R

Prabhanjan N. Tattar, Suresh Ramaiah, B. G. Manjunath

Publisher Resources

ISBN: 9781491922606Errata Page