【问题标题】:align ggplot map plots with coord_equal()用 coord_equal() 对齐 ggplot 地图
【发布时间】:2020-07-15 07:43:11
【问题描述】:

我无法对齐两张地图。我在下面使用一个可重现的例子:

library(ggplot2)
library(cowplot)
world <- map_data("world")

pl2= ggplot() +
  geom_polygon(data=world, aes(x=long, y=lat, group=group)) +
  theme_bw()+
  coord_equal()
pl1 <- ggplot() +
  geom_polygon(data=world, aes(x=long, y=lat, group=group, color=group)) +
  coord_equal()
plot_grid(pl2, pl1 + theme(legend.justification = c(0,1)), align="h",axis = "bt")

我尝试了各种方法,例如设置图形宽度和高度,尝试scale=,align="h",axis = "bt" 的各种选项 我还尝试了plot_grid(pl2, pl1+ theme(legend.position = "none"), align="h", scale=c(1,1)),然后再次添加legend legend &lt;- get_legend(pl1) 和plot_grid。 当我使用 coord_equal 时,我也有大量的空白,我无法摆脱(我没有保存图表,只是显示它)

【问题讨论】:

    标签: r dictionary ggplot2 cowplot


    【解决方案1】:

    我更喜欢使用 patchwork 包来对齐绘图、简单的框架(具有许多附加功能),并且开箱即用地满足您的需求。

    library(patchwork)
    pl2 + pl1
    

    【讨论】:

    • 就世界地图上的空白而言,我相信是graphics device issue。
    • @caldwest,是的,确实如此!我设置了比例宽度:长度 1:4 和空白消失
    猜你喜欢
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    相关资源
    最近更新 更多