library(raster)
library(ggplot2)
map.shp <- getData('GADM', country='FRA', level=1)
plot(map.shp)
ggplot(mtcars, aes(x = hp, y = disp)) + geom_point()
How can I put the map.shp
on the right side of the ggplot as a small inset.
I think there are multiple ways to achieve this but a simple way would be to use cowplot
and ggdraw
:
I am using sf
along with geom_sf
from the development version of ggplot2
available at 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)
Sorry the shapefile seemed to be rendering really slow for me so couldn't play around with the positioning too much. Is something like this what you were after?