【发布时间】:2018-11-11 22:00:40
【问题描述】:
library(raster)
library(ggplot2)
map.shp <- getData('GADM', country='FRA', level=1)
plot(map.shp)
ggplot(mtcars, aes(x = hp, y = disp)) + geom_point()
如何将map.shp 放在 ggplot 的右侧作为小插图。
【问题讨论】:
library(raster)
library(ggplot2)
map.shp <- getData('GADM', country='FRA', level=1)
plot(map.shp)
ggplot(mtcars, aes(x = hp, y = disp)) + geom_point()
如何将map.shp 放在 ggplot 的右侧作为小插图。
【问题讨论】:
我认为有多种方法可以实现这一点,但一个简单的方法是使用 cowplot 和 ggdraw:
我正在使用sf 和geom_sf 的ggplot2 开发版devtools::install_github("hadley/ggplot2") 中的devtools::install_github("hadley/ggplot2")
require(ggplot2)
require(cowplot)
require(sf)
require(raster)
map.shp <- getData('GADM', country='FRA', level=1) %>% st_as_sf()
plot.cars <- ggplot(mtcars, aes(x = hp, y = disp)) + geom_point()
plot.map <- ggplot() + geom_sf(data=map.shp)
inset_map <- ggdraw() +
draw_plot(plot.cars, 0, 0, 1, 1)+
draw_plot(plot.map, 0.5, 0.52, 0.5, 0.4)
抱歉,shapefile 对我来说似乎渲染得很慢,所以无法过多地调整定位。你追求的是这样的东西吗?
【讨论】: