I am new to this book and get an error with the example code for the first chapter. I installed the latest version of R 3.2.3 and RStudio. I installed package_install.R given by the sample code and then installed ggplot2 by myself. When I run the code ufo_sightings.R, I got an error as follow
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Error in strsplit(unitspec, " ") : non-character argument
In addition: Warning message:
Removed 1 rows containing non-finite values (stat_bin).
I am new to R so I have no idea what is wrong. Can anyone help? Is it because I used the latest version of R?
Edit: I think I found the reason. If I change ggplot to 1.01 version, it worked fine. If I upgrade it to 2.0.0 the error occurs. I guess it is a bug?
The problem lies in the ggplot function scale_x_date. In the original code this is coded as:
quick.hist <- ggplot(ufo.us, aes(x = DateOccurred)) +
geom_histogram() +
scale_x_date(breaks = "50 years")
The breaks in scale_x_date has been adjusted to date_breaks. If you adjust the code to the following it works.
quick.hist <- ggplot(ufo.us, aes(x = DateOccurred)) +
geom_histogram() +
scale_x_date(date_breaks = "50 years", date_labels = "%Y")
In the rest of the code where you see ggplot and scale_x_date, you will have to adjust the breaks into date_breaks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With