使用ggmap绘制地图时出错

时间:2016-11-02 03:40:24

标签: r ggplot2 ggmap

当我尝试下面的代码时,我收到以下错误消息。

my.Map <- get_map(location ="Singapore",source = "osm",zoom = 10)
 ggmap(my.Map)

错误讯息:

  

zero_range(from)出错:x必须是长度1或2

我已尝试使用多个示例并重新加载包,我无法弄清楚如何解决这个问题,因为它只涉及查询谷歌地图并绘制它们。

以下是我的sessionInfo

R version 3.3.0 (2016-05-03) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.11.5 (El Capitan)

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] ggmap_2.6.1        ggplot2_2.1.0.9001

loaded via a namespace (and not attached):  [1] Rcpp_0.12.7       plyr_1.8.4        tools_3.3.0       digest_0.6.10      [5] evaluate_0.9      tibble_1.2        gtable_0.2.0      lattice_0.20-34  [9] png_0.1-7         shiny_0.14        rstudioapi_0.6    mapproj_1.2-4     [13] yaml_2.1.13       proto_0.3-10      stringr_1.1.0     knitr_1.14        [17] RgoogleMaps_1.4.1 maps_3.1.1  grid_3.3.0        R6_2.1.3          [21] jpeg_0.1-8        rmarkdown_1.1     bookdown_0.1      sp_1.2-3          [25] reshape2_1.4.1    magrittr_1.5      scales_0.4.0.9003 htmltools_0.3.5  [29] assertthat_0.1    mime_0.5          xtable_1.8-2      colorspace_1.2-6  [33] geosphere_1.5-5   httpuv_1.3.3      labeling_0.3      stringi_1.1.1     [37] miniUI_0.1.1      lazyeval_0.2.0    munsell_0.4.3     rjson_0.2.15

my.Map的描述

str(my.Map)
chr [1:607, 1:607] "#F2EFE9" "#F2EFE9" "#F2EFE9" "#F2EFE9" "#F2EFE9" ...
- attr(*, "class")= chr [1:2] "ggmap" "raster"
- attr(*, "bb")='data.frame':   1 obs. of  4 variables:
..$ ll.lat: num 0.912
..$ ll.lon: num 103      ..$ ur.lat: num 1.79
..$ ur.lon: num 104
- attr(*, "source")= chr "osm"
- attr(*, "maptype")= chr "openstreetmap"
- attr(*, "scale")= num 575000

1 个答案:

答案 0 :(得分:0)

问题似乎与Open Street Map(osm)有关。 ?get_openstreetmap会为您提供有关此问题的更多详细信息。

  

从download.file收到错误消息,消息HTTP状态为“503 Service Unavailable”。您可以通过设置urlonly = TRUE,然后在Web浏览器中输入URL来确认。解决方案是(1)更改源或(2)等待OSM服务器重新启动。

如果您稍微更改代码以使用Google作为来源,则可以使用。

my.Map <- get_map(location ="Singapore",source = "google")
ggmap(my.Map)

Rendered from the code above