R语言:使用ggmap将地图插入另一个地图

时间:2019-05-08 02:25:41

标签: r ggplot2 ggmap

我正在尝试将地图插入另一个地图。而且即使一次有效,我也经常中断R Studio。

第一张地图:卢森堡

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)

第二张地图:欧洲

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

第三张地图:我的问题!

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

我尝试了

的不同组合
 geom_polygon(data = shapefile_df, aes(x = long, y = lat, group = group))

但是,在我看来,问题出在我用来在两个地图之间进行组合的方式上。

预期结果是卢森堡成为欧洲地图的形状。

1 个答案:

答案 0 :(得分:0)

## 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

相关问题