首页 > 解决方案 > 为什么 ggplot2 会根据 coord_map 的 xlim 生成地图偏移量?

问题描述

有人可以解释一下,为什么 ggplot 在地图中产生偏移?我在地图 A 和 B 的两个代码中唯一更改的是 xlim。如果我需要地图 A 范围的地图,我不明白为什么会产生此错误也无法解决此问题。感谢您的帮助和时间。

使用地图 A 的代码生成的偏移量

world <- rworldmap::getMap(resolution = "low")
fty_world <- ggplot2::fortify( world)

## map A with offset in the image
ggplot() +
    geom_polygon( data = fty_world,
                                aes( x = long,
                                     y = lat, 
                                         group = group), 
                                         fill = "white",  
                                         color = "grey50") +
    coord_map( xlim = c( -3, 14), 
               ylim = c( 43, 54))

## map B without offset
ggplot() +
    geom_polygon( data = fty_world,
                                aes( x = long,
                                     y = lat, 
                                         group = group), 
                                         fill = "white",  
                                         color = "grey50") +
    coord_map( xlim = c( -2, 14), 
               ylim = c( 43, 54))

标签: rggplot2rworldmap

解决方案


推荐阅读