我想通过ggmap在地图上显示来自URL的geojson文件。当我通过plot()
绘制几何图形时,它就起作用了:
intensity_url <- "https://earthquake.usgs.gov/realtime/product/shakemap/us6000jllz/us/1675733020783/download/cont_mmi.json" intensity <- geojson_read(data_url, what = "sp") intensity <- sf::read_sf(intensity_url) plot(intensity$geometry)
输出:
但是当我在ggmap上添加这个几何体时,它显示了一个错误:
bbox <- c(28.841667, 29.866555, 48.266738, 44.65) myMap <- get_stamenmap(bbox=bbox) ggmap(myMap) + geom_sf(aes(long, lat, group = group), data = intensity$geometry)
错误消息:
ℹ Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL. ℹ 3024 tiles needed, this may take a while (try a smaller zoom?) Warning: Ignoring unknown aesthetics: x and yCoordinate system already present. Adding new coordinate system, which will replace the existing one.Error in `geom_sf()`: ! Problem while computing aesthetics. ℹ Error occurred in the 4th layer. Caused by error in `FUN()`: ! object 'group' not found Backtrace: 1. base (local) `<fn>`(x) 2. ggplot2:::print.ggplot(x) 4. ggplot2:::ggplot_build.ggplot(x) 5. ggplot2:::by_layer(...) 12. ggplot2 (local) f(l = layers[[i]], d = data[[i]]) 13. l$compute_aesthetics(d, plot) 14. ggplot2 (local) compute_aesthetics(..., self = self) 15. ggplot2:::scales_add_defaults(...) 16. base::lapply(aesthetics[new_aesthetics], eval_tidy, data = data) 17. rlang (local) FUN(X[[i]], ...) Error in geom_sf(aes(long, lat, group = group), data = intensity$geometry) : ℹ Error occurred in the 4th layer. Caused by error in `FUN()`: ! object 'group' not found
注意:当我从aes中删除group
时,它将显示相同的错误,并带有long。
您知道为什么显示此错误吗?