将 ggplot 地图图与 coord_equal() 对齐
align ggplot map plots with coord_equal()
我在对齐两张地图时遇到问题。我正在使用下面的可重现示例:
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 <- get_legend(pl1)
和 plot_grid
。
当我使用 coord_equal 时,我也有大量的白色 space,我无法摆脱(我没有保存图表,只是显示它)
我更喜欢使用 patchwork
包来对齐图,简单的框架(具有许多附加功能),开箱即用,可以满足您的需求。
library(patchwork)
pl2 + pl1
我在对齐两张地图时遇到问题。我正在使用下面的可重现示例:
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 <- get_legend(pl1)
和 plot_grid
。
当我使用 coord_equal 时,我也有大量的白色 space,我无法摆脱(我没有保存图表,只是显示它)
我更喜欢使用 patchwork
包来对齐图,简单的框架(具有许多附加功能),开箱即用,可以满足您的需求。
library(patchwork)
pl2 + pl1