Error in strsplit (unitspec, "") in machine learning code for hackers

I am new to this book and get an error message with sample code for the first chapter. I installed the latest version of R 3.2.3 and RStudio. I installed the package_install.R specified by the sample code, and then installed ggplot2 myself. When I run the ufo_sightings.R code, I got an error following

`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 a reason. If I change ggplot to version 1.01, it works fine. If I upgrade it to 2.0.0, an error will occur. I think this is a mistake?

+5
source share
2 answers

The problem is the ggplot scale_x_date function. In the source code, this is encoded as:

 quick.hist <- ggplot(ufo.us, aes(x = DateOccurred)) + geom_histogram() + scale_x_date(breaks = "50 years") 

Gaps in scale_x_date have been adjusted to date_breaks. If you change the code to the next, it will work.

 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 have to set breaks to date_breaks.

+9
source

For me, both options for using ggplot 1.0.1 and setting date_breaks for 10 years for DateReported for 50 years for DateOccured work absolutely fine and create a nice visualization.

 quick.hist <- ggplot(ufo.us, aes(x = DateOccurred)) + geom_histogram() + scale_x_date(date_breaks = "50 years", date_labels = "%Y") quick.hist <- ggplot(ufo.us, aes(x = DateReported)) + geom_histogram() + scale_x_date(date_breaks = "10 years", date_labels = "%Y") 
0
source

Source: https://habr.com/ru/post/1238994/


All Articles