【问题标题】:How can I zoom in a ggmap plot that uses shapefiles?如何放大使用 shapefile 的 ggmap 图?
【发布时间】:2017-03-13 23:29:15
【问题描述】:

我正在尝试绘制一张欧洲地图,其中每个国家都根据某个数值填充颜色 - 我认为 shapefile(我在这里得到http://www.naturalearthdata.com/downloads/10m-cultural-vectors/)和 ggmap 应该没有问题。但是它只适用于非常大的地图,但我无法正确放大。

我尝试通过设置xlim()ylim() 来做到这一点,但是由于我在边缘处切断了形状,因此 R 连接了不应该连接的点。对于 ggplot,我可以改用 coord_fixed(xlim, ylim) 来解决这个问题,但是当我的 ggmap-plot 应用同样的问题时,国家形状和地图将不再适合彼此。

ggmap with wrong shapes

这是我用于绘图的代码:

my.map <- get_map(location = "europe", source = "google", maptype = "satellite", zoom = 3)

ggmap(my.map) + 
  geom_polygon(aes(x = long, y = lat, group = group), fill = eu$value, size = .2, color = 'green', data = eu, alpha = 0.5) +
  coord_fixed(xlim = c(0, 35),  ylim = c(35, 65), ratio = 1.6)

有人知道我该如何解决这个问题吗?
(我知道它适用于 ggplot,但我真的很想使用 ggmap。)

谢谢!

【问题讨论】:

    标签: r zooming shapefile ggmap


    【解决方案1】:

    使用coord_map() 代替coord_fixed()

    my.map <- get_map(location = "europe", source = "google", maptype = "satellite", zoom = 3)
    ggmap(my.map)+
      geom_polygon(aes(x=long, y = lat, group = group), fill='white', size=.2, color='green', data=eu, alpha=0.5)+
      coord_map(xlim=c(0, 35), ylim=c(35, 65))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-23
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 2019-08-12
      • 2015-03-10
      • 2019-01-04
      相关资源
      最近更新 更多