334394 (2) [Avatar] Offline
#1
When I run Listing 3.7 in RStudio, I receive the following error:
Error: Labels can only be specified in conjunction with breaks

I'm running R version 2.12.1 (2010-12-16), and I could run Listing 3.6 without a problem.
In fact, the issue is specifically scale_x_continuous(labels=dollar). A 'breaks' value is needed, but no indication of this is given in the example.

I'm getting a comparable error with scale_x_log10 in Listing 3.8, too.
john.mount (79) [Avatar] Offline
#2
The issue is almost certainly that at least one of your R/ggplot2/scales is too far out of date. ggplot2 in particular (and the scales controls most definitely) have had a lot of changes/improvements in the last few years. Your comment mentioned you are using R version 2.12.1 (2010-12-16), which is four years old. I would suggest checking your version of ggplot2 and upgrading it and R if possible.

Here is code identical to Listing 3.7 https://github.com/WinVector/zmPDSwR/blob/master/CodeExamples/c03_Exploring_data/00026_example_3.7_of_section_3.2.1.R (just faked up the data for convenience) confirming that scale_x_continuous() works as used in the book. This is using scales_0.2.4, ggplot2_1.0.0, R version 3.1.2 (2014-10-3). These are all the latest at the time of this note.

library(ggplot2)
library(scales)
custdata = data.frame(income=rnorm(2000))
ggplot(custdata) + geom_density(aes(x=income)) +
  scale_x_continuous(labels=dollar)
334394 (2) [Avatar] Offline
#3
That was indeed the case. I think I updated RStudio and assumed the updates would include R itself. Things are working as described.

Thank you for taking the time to answer.