oswaldosantos / ggsn

R package to add north symbols and scale bars to maps created with ggplot or ggmap
http://oswaldosantos.github.io/ggsn/
GNU General Public License v2.0
161 stars 9 forks source link

Example code not working -- "non-numeric argument to mathematical function" error #13

Closed brianwood1 closed 7 years ago

brianwood1 commented 7 years ago

Hello- I have tried adding a scalebar to a map created in ggplot2, following the code provided in the package documentation, and I have found that the example code no longer works. I've hit the same error when trying to add a scale bar to a map I've created using my own data. Here is the script that I am running, which generates the error. This code is copied and pasted directly from the package documentation file, "ggsn.pdf", page 7:

library(rgdal); library(broom) dsn <- system.file('extdata', package = 'ggsn') map <- readOGR(dsn, 'sp') map@data$id <- 1:nrow(map@data) map.df <- merge(tidy(map), map, by = 'id') ggplot(data = map.df, aes(long, lat, group = group, fill = nots)) + geom_polygon() + coord_equal() + geom_path() + scale_fill_brewer(name = 'Animal abuse\nnotifications', palette = 8) + scalebar(map.df, dist = 5, dd2km = TRUE, model = 'WGS84')

The error that this generates is as follows:

Error in FUN(left, right) : non-numeric argument to binary operator

For reproducibility, here is my RSessionInfo:

`R version 3.3.3 (2017-03-06) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: macOS Sierra 10.12.3

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] broom_0.4.2 knitr_1.15.1 stringr_1.0.0 readxl_0.1.1 gridExtra_2.2.1
[6] lattice_0.20-34 animation_2.4 dismo_1.0-15 raster_2.5-8 geosphere_1.5-1
[11] wesanderson_0.3.4 scales_0.4.1 maptools_0.9-2 roxygen2_5.0.1 adehabitatHR_0.4.14 [16] adehabitatLT_0.3.20 CircStats_0.2-4 boot_1.3-18 MASS_7.3-45 adehabitatMA_0.3.10 [21] ade4_1.7-4 deldir_0.1-12 rgdal_1.1-10 sp_1.2-4 ggmap_2.6.1
[26] RMySQL_0.10.9 DBI_0.5-1 ggsn_0.4.0 ggplot2_2.2.1 devtools_1.12.0

loaded via a namespace (and not attached): [1] reshape2_1.4.1 colorspace_1.2-6 foreign_0.8-67 withr_1.0.1 jpeg_0.1-8
[6] plyr_1.8.3 munsell_0.4.3 gtable_0.2.0 RgoogleMaps_1.2.0.7 mapproj_1.2-4
[11] psych_1.7.3.21 memoise_1.0.0 labeling_0.3 parallel_3.3.3 curl_0.9.7
[16] proto_0.3-10 Rcpp_0.12.9 mnormt_1.5-5 rjson_0.2.15 png_0.1-7
[21] digest_0.6.12 stringi_1.1.1 dplyr_0.5.0 RJSONIO_1.3-0 grid_3.3.3
[26] tools_3.3.3 magrittr_1.5 maps_3.1.0 lazyeval_0.2.0 tibble_1.2
[31] tidyr_0.6.0 rsconnect_0.4.3 rstudioapi_0.5 assertthat_0.1 httr_1.1.0
[36] R6_2.2.0 nlme_3.1-131 git2r_0.15.0`

oswaldosantos commented 7 years ago

Hi, Could you upgrade to R 3.4.0 to see if the problem persist? I ran the code without problems.