Errata

R Graphics Cookbook

Errata for R Graphics Cookbook

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed, PDF, ePub
Page 4
sample code in the first paragraph of Solution

'library(xslx)' should be 'library(xlsx)'

Anonymous  Jun 28, 2015 
PDF
Page 387
dendogram entry

Typo: "dendogram" should be "dendrogram".

Winston Chang
Winston Chang
 
Jul 08, 2013  Jul 12, 2013
PDF
Page 361
First sentence of See Also section

Typo.

Old version:
"If you want to calculate standard error..."

Corrected version:
"If you want to calculate standard errors..."

Winston Chang
Winston Chang
 
Jul 08, 2013  Jul 12, 2013
PDF
Page 356
Last full paragraph (below Fig 15-2)

Change of wording. Instead of "unique", use "distinct".

Old version:
"... forming a group for each unique combination..."

Corrected version:
"... forming a group for each distinct combination..."

Winston Chang
Winston Chang
 
Jul 08, 2013  Jul 12, 2013
PDF
Page 306
In See Also section

Typo: The text says "?mosiacplot" but it should be "?mosaicplot".

Winston Chang
Winston Chang
 
Jul 08, 2013  Jul 12, 2013
PDF
Page 290
In Solution section

Typo in capitalization. In two places, the text says "Postscript", but it should be "PostScript". (This is in the text; the code is correct.)

Winston Chang
Winston Chang
 
Jul 08, 2013  Jul 12, 2013
PDF
Page 270
Last row, second column of table

Typo: The text says "principle", but it should be "principal".

Winston Chang
Winston Chang
 
Jul 08, 2013  Jul 12, 2013
PDF
Page 106
Last paragraph

The word "either" is awkward here.

Old version:
"... you can either increase or decrease..."

Corrected version:
"... you can increase or decrease..."

Winston Chang
Winston Chang
 
Jul 08, 2013  Jul 12, 2013
PDF
Page 87
Figure 5-15 caption

Typo: The word "shows" is used, but it should be "shown".

Winston Chang
Winston Chang
 
Jul 08, 2013  Jul 12, 2013
Printed
Page 143-145
Figs 6-32 to 6-34

I think a figure got left out (maybe 6-32) and the next three or four figures were affected as a result.

A separate issue is that 6-34 doesn't have a marginal rug to it, as the caption describes. I don't see any code in the neighboring pages that specify a rug geom/annotation.

Note from the Author or Editor:
There are a few related errors:
* The correct image for Figure 6-32 was accidentally dropped.
* Figures 6-33, 6-34, and 6-35 were accidentally shifted back one.
* The caption for 6-34 is incorrect.

Corrections:
* Figure 6-32 should have a different figure (which will appear in the next printing). The height of this figure should be reduced to be the same as 6-30 and 6-31.
* The image in Figure 6-32 should move to Figure 6-33.
* The image in Figure 6-33 should move to Figure 6-34.
* The image in Figure 6-34 should move to Figure 6-35 (note the slight difference in the legend). The height of 6-34 should be decreased to be the same as 6-33. The image presently in Figure 6-35 should not be used at all.
* The caption for 6-34 should read: "Left: with ..density.. mapped to fill; right: with points, and ..density.. mapped to alpha."

wibeasley  Jun 08, 2013  Jul 12, 2013
Printed
Page 362
first full block of code -on the last line

where is 'sqrtn' defined? Is this supposed to be 'sqrt(n)'?

Note from the Author or Editor:
There is a missing opening parenthesis. Instead of `sqrtn)`, it should be `sqrt(n)`.

Old code:
ddply(cabbages, c("Cult", "Date"), summarise,
Weight = mean(HeadWt, na.rm=TRUE),
sd = sd(HeadWt, na.rm=TRUE),
n = sum(!is.na(HeadWt)),
se = sd / sqrtn) )

Corrected code:
ddply(cabbages, c("Cult", "Date"), summarise,
Weight = mean(HeadWt, na.rm=TRUE),
sd = sd(HeadWt, na.rm=TRUE),
n = sum(!is.na(HeadWt)),
se = sd / sqrt(n) )

wibeasley  Jun 08, 2013  Jul 12, 2013
Printed
Page 327
after 'Solution'

In the sentence, "One method is to open the PDF graphics device with png()", the 'PDF' term should be replaced with 'PNG'.

Note from the Author or Editor:
The text contains "PDF", but it should be "PNG".

Old text:
"One method is to open the PDF graphics device with png() ..."

Corrected text:
"One method is to open the PNG graphics device with png() ..."

wibeasley  Jun 08, 2013  Jul 12, 2013
Printed
Page 319
2nd paragraph

When the book was written, I bet it wasn't known that the next version would be 3.0, not 2.16 .

Note from the Author or Editor:
The text refers to R 2.16, but it should be R 3.0.

Instead of "This bug should be fixed in R 2.16", it should say "This bug was fixed as of R 3.0".

wibeasley  Jun 08, 2013  Jul 12, 2013
Printed
Page 317
Figure 13-37

Figure 13-37 looks like a duplication of Fig 13-36. The Assault scale is still on a finely grained continuum, not the five cuts that I think was intended.

Note from the Author or Editor:
The image in Figure 13-37 is incorrect (the corrected version will appear in next printing).

wibeasley  Jun 08, 2013  Jul 12, 2013
Printed
Page 275
last paragraph

In the sentence, "The first two rows of the data frame", I believe 'rows' should 'columns'

Note from the Author or Editor:
The text has "rows" where it should be "columns".

Old text:
"The first two rows of the data frame..."

Corrected text:
"The first two columns of the data frame..."

wibeasley  Jun 08, 2013  Jul 12, 2013
Printed
Page 39
2nd sentence

To prevent labels from being clipped, it says "See Recipe 8.4". But Recipe 8.4 is "Changing the order of items on a categorical axis", and I don't see a way to use this to prevent the labels being clipped a the border of the plot.

Note from the Author or Editor:
There was a reference to the wrong recipe for controlling the range of a continuous axis.

Old text:
"To remedy this, see Recipe 8.4."

Corrected text:
"To remedy this, see Recipe 8.2."

wibeasley  Jun 08, 2013  Jul 12, 2013
PDF
Page 31
"Discussion" section

Since the default width of position_dodge() is NULL (see http://svitsrv25.epfl.ch/R-doc/library/ggplot2/html/position_dodge.html), the whole discussion section on this page is incorrect.

Note from the Author or Editor:
There's a simplification of how `width` works in `position_dodge()` which may be slightly confusing.


Old text:
To be more precise, the value of `width` in `position_dodge()` is the same as `width` in `geom_bar()`.

Corrected text:
To be more precise, the value of `width` in `position_dodge()` is `NULL`, which tells ggplot2 to use the same value as the `width` from `geom_bar()`.


(The text in backticks should be rendered as code in the output.)

Joseph  Apr 16, 2013  Jul 12, 2013
PDF
Page 309
Third paragraph, first example source code block.

The example relies on the map_data() routine. The text does not state that this routine is provided by the ggplot2 package and not the maps package. Therefore, the examples will not work if the ggplot2 library is not loaded.

Note from the Author or Editor:
The `map_data()` function is in ggplot2. The code is correct (since ggplot2 is assumed to be loaded for all the examples in the book), but to make it clear, a comment should be added to that line of code.

Old:
states_map <- map_data("state")

Corrected:
states_map <- map_data("state") # ggplot2 must be loaded to use map_data()

John Cardente  Mar 27, 2013  Jul 12, 2013
Printed
Page 82
3rd paragrph

The code on page 82 cannot produce the Figure 5-10, I think the legend on the figure and the "fill = ageYear" are different, also I tried the second part of the code, changed the fill = ageYear to fill = weightLb, but cannot get the same legend as on the right graph on Figure 5-10.

I guess probably we should change the "breaks" or "guide" command, but still couldn't get the legend.

Could you please try it again!

Thanks!

Shu

Note from the Author or Editor:
In the code, weightLb and ageYear were swapped. Also, in the code for the second graph, the breaks need to be changed for the corrected variable mappings.

Old code:
ggplot(heightweight, aes(x=weightLb, y=heightIn, fill=ageYear)) +
geom_point(shape=21, size=2.5) +
scale_fill_gradient(low="black", high="white")

# Using guide_legend() will result in a discrete legend instead of a colorbar
ggplot(heightweight, aes(x=weightLb, y=heightIn, fill=ageYear)) +
geom_point(shape=21, size=2.5) +
scale_fill_gradient(low="black", high="white", breaks=12:17,
guide=guide_legend())



Corrected code:
ggplot(heightweight, aes(x=ageYear, y=heightIn, fill=weightLb)) +
geom_point(shape=21, size=2.5) +
scale_fill_gradient(low="black", high="white")

# Using guide_legend() will result in a discrete legend instead of a colorbar
ggplot(heightweight, aes(x=ageYear, y=heightIn, fill=weightLb)) +
geom_point(shape=21, size=2.5) +
scale_fill_gradient(low="black", high="white", breaks=seq(70, 170, by=20),
guide=guide_legend())

Shu Guo  Mar 16, 2013  Jul 12, 2013
Printed
Page 217
Top graph

Figure 9-5 is a *correct* duplicate to Figure 9-6 on page 217. Figure 9-6 has an error in the top left graph. Recipe 9.3. Using Themes generates a totally different graph than that of Figure 9-5. Figure 9-6 should be replaced with that of Figure 9-5, and the correct graph for Recipe 9.4. should replace that of Figure 9-5.

Note from the Author or Editor:
The picture in Figure 9-5 should be used in Figure 9-6, and a different (missing) figure should be used in 9-5. With the new image, the height of Figure 9-5 should be reduced to about half ow what it presently is.

Brannon Walden  Feb 19, 2013  Jul 12, 2013
PDF
Page 76
figure 5-4

On the left side there two lines. How they were created? Code in book didn't create them.

Note from the Author or Editor:
Figure 5-4 is incorrect; the regressions lines shouldn't be there.

Anonymous  Feb 02, 2013  Jul 12, 2013
PDF
Page 37
code snippet under image & data

There is:
ddply(cabbage_exp, "Date", transform,
percent_weight = Weight / sum(Weight) * 100)

It should be (variable ce is used later in next code snippet):
ce <- ddply(cabbage_exp, "Date", transform,
percent_weight = Weight / sum(Weight) * 100)

Note from the Author or Editor:
The results of the ddply() command should have been saved in a variable `ce`, but they were not.

Original code:
ddply(cabbage_exp, "Date", transform,
percent_weight = Weight / sum(Weight) * 100)

Corrected code:
ce <- ddply(cabbage_exp, "Date", transform,
percent_weight = Weight / sum(Weight) * 100)

Anonymous  Feb 01, 2013  Jul 12, 2013
PDF
Page 251
Solution:

> ggplot(birthwt, aes(x=bwt)) + geom_histogram(fill="red"), colour="black"
Error: unexpected ',' in "ggplot(birthwt, aes(x=bwt)) + geom_histogram(fill="red"),"
>


Maybe, It should be
ggplot(birthwt, aes(x=bwt)) + geom_histogram(fill="red", colour="black")

Note from the Author or Editor:
A closing parenthesis is in the wrong place. The line that says:
ggplot(birthwt, aes(x=bwt)) + geom_histogram(fill="red"), colour="black"

should instead be:
ggplot(birthwt, aes(x=bwt)) + geom_histogram(fill="red", colour="black")

Surachart Opun  Jan 16, 2013  Jul 12, 2013
PDF
Page 34
3rd paragraph

libary(plyr) # Needed for desc()

It should be.

library(plyr) # Needed for desc()

Note from the Author or Editor:
The `libary(plyr)` is misspelled. It should instead be `library(plyr)`.

Surachart Opun  Jan 16, 2013  Jul 12, 2013
PDF
Page 22, 23, 24
ggplot code on each page

The three code snippets draws the graphs as expected, but also produce a message concerning stat="bin" and stat="identity". Possibly the the code snippets need stat="identity".

Note from the Author or Editor:
The code chunks for each plot should have stat="identity" added to each geom_bar():

ggplot(cabbage_exp, aes(x=Date, y=Weight, fill=Cultivar)) +
geom_bar(position="dodge", stat="identity")


ggplot(cabbage_exp, aes(x=Date, y=Weight, fill=Cultivar)) +
geom_bar(position="dodge", colour="black", stat="identity") +
scale_fill_brewer(palette="Pastel1")


ggplot(ce, aes(x=Date, y=Weight, fill=Cultivar)) +
geom_bar(position="dodge", colour="black", stat="identity") +
scale_fill_brewer(palette="Pastel1")

Sandy Muspratt  Jan 10, 2013  Jul 12, 2013
A-2?
Figure A-5

Figure A-5 is the same as Figure A-4, but is supposed to have the Avalue and Bvalue properties swapped, as in Figure A2 (contrasted with A-1)

Note from the Author or Editor:
The image in Figure A-5 is incorrect (the corrected version will appear in next printing).

Steve Haddock  Jan 08, 2013  Jul 12, 2013