【发布时间】:2023-03-23 23:42:02
【问题描述】:
以前的一些问题的主题 - 例如。 this。我无法让 sf 层在 ggmap 层上呈现。
require(ggmap)
require(raster)
require(sf)
target_bbox <- c(left = -0.65, bottom = 51.2, right = 0.45, top = 51.8)
map = get_stamenmap(target_bbox, zoom = 9, maptype = 'toner-2010')
# can test this with: ggmap(map)
e = extent(list(x = c(-0.65, 0.45), y = c(51.2, 51.8)))
r = raster(volcano)
crs(r) = CRS("+proj=longlat +datum=WGS84")
p = raster::rasterToPolygons(r)
sf = st_as_sf(p) %>% st_transform(3857)
# test with: ggplot() + geom_sf(data = sf, aes(fill = layer), col = NA)
ggmap(map) +
geom_sf(data = sf, aes(fill = layer), col = NA, alpha = 0.4, inherit.aes = FALSE)
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
坐标系冲突但没有错误,但没有图层可见。任何建议都非常感谢。
This github solution - 使用自定义函数 ggmap_bbox() 从 ggmap 对象中提取边界框 - 只成功地在上面添加另一个警告:
Warning message:
In st_is_longlat(x) :
bounding box has potentially an invalid value range for longlat data
【问题讨论】: