I have two ggplots that I'm combining with ggarrange()
. One plot has long labels, that I wrap with scale_x_discrete(labels = function(x) str_wrap(x, width = 10))
, where str_wrap()
is from the stringr
package. However, when I combine them, the first panel is reduced in height to accommodate for the space required by the wrapped labels. I already tried all kinds of variations of adjusting the margins both in theme(plot.margin = margin())
as well as axis.text.x=element_text(margin = unit(c(), "cm"))
, to no avail. I'm probably missing something very obvious, but I just can't get the panels to match in height, regardless of how much space is needed by the axis labels.
Thanks!
plot1 <- ggplot(data=dat, aes(x=x, y=y)) +
theme_bw() +
geom_point(size=2) +
labs(x='', y='', title='') +
scale_x_discrete(labels = function(x) str_wrap(x, width = 10))
plot2 <- ggplot(data=dat, aes(x=x2, y=y2)) +
theme_bw() +
geom_point(size=2) +
labs(x='', y='', title='')
ggarrange(plot1, plot2, ncol=2)