Reputation: 1713
I am having trouble aligning two maps. I am using a reproducible example below:
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")
I tried various things like setting the figure widths and heights, trying scale=
,various options from align="h",axis = "bt"
I also tried plot_grid(pl2, pl1+ theme(legend.position = "none"), align="h", scale=c(1,1))
and then add legend legend <- get_legend(pl1)
with plot_grid
again.
I also have a crazy amount of white space when I use coord_equal, that I can't get rid of ( I am not saving the graph, just displaying it)
Upvotes: 4
Views: 308
Reputation: 5956
I prefer using the patchwork
package for aligning plots, simple framework (with lots of additional functionality), and out of the box does what you want here.
library(patchwork)
pl2 + pl1
Upvotes: 4