hpy*_*hpy 2 maps r geospatial ggplot2 ggmap
美好的一天,
假设我library(ggmap)在R中使用此地图:
ggmap(get_map(location = c(lon = -81.38630, lat = 19.30340), source = "stamen", maptype = "terrain", zoom = 14))
Run Code Online (Sandbox Code Playgroud)
这使:
如何在此图像上添加一个小的上下文插图(可能在左上方附近?)以显示更大的地理区域?在这个小插图中,我希望它有一个框,该框勾勒出较大的地图适合的位置。
谢谢您的帮助。
这是基于grid视口使用的可能解决方案。
library(ggmap)
library(grid)
map1 <- get_map(location = c(lon = -81.38630, lat = 19.30340),
maptype = "terrain", zoom = 14)
map2 <- get_map(location = c(lon = -81.38630, lat = 19.30340),
maptype = "terrain", zoom = 12)
p1 <- ggmap(map1)
g1 <- ggplotGrob(p1)
grid.draw(g1)
pushViewport( viewport(x=0.25, y=0.8, w=.3, h=.3) )
xy <- data.frame(x=c(-81.41,-81.41,-81.36,-81.36,-81.41),
y=c(19.33,19.28,19.28,19.33,19.33))
p2 <- ggmap(map2) +
geom_path(data=xy, aes(x,y), color="red", lwd=1) +
theme_void()
g2 <- ggplotGrob(p2)
grid.draw(g2)
grid.rect(gp=gpar(col="white", lwd=5))
popViewport()
Run Code Online (Sandbox Code Playgroud)