简体   繁体   中英

R language: Insert a map into another using ggmap

I am trying to insert a map into another. And even when one time it worked, frequently I break R Studio.

First map: Luxemburgo

library(rgdal)     
library(ggplot2)   
library(ggmap)     
library(raster)

 shapefile_lux <- getData('GADM', country='LUX', level=0)
 shapefile_lux <- fortify(shapefile_lux)


 map <- ggplot() +
        geom_path(data = shapefile_lux, 
            aes(x = long, y = lat, group = group),
            color = 'red', fill = 'white', size = .2)

 map_projected <- map +
         coord_map()


 print(map_projected)

Second map: Europe

 continent <- qmap('europe', zoom = 3, source="stamen")

Third map: My problem!

 continent +
        geom_polygon(data = shapefile_df, aes(x = long, y = lat, group = group)) 

I tried with different combinations for

 geom_polygon(data = shapefile_df, aes(x = long, y = lat, group = group))

But, it seems to me that the problem is in way that I am using to make the combination between both maps.

The expected results is the shape of Luxemburg into the map of Europe.

## Luxemburgo
data <- shapefile_lux
qmap('europe', zoom = 4, maptype = 'satellite') +
geom_polygon(aes(x = long, y = lat, group = group), data = data,
              colour = 'white', fill = 'black', alpha = .4, size = .3)

1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM