How do I make two graphs in cowplot (arranged side by side) different heights? I understand I can't use rel_height as this only works if the are on top of each other
As far as I know (and as you mention),
rel_height only works with multiple rows. Another option could be the
patchwork package. Example shown below.
library(tidyverse) library(patchwork) g1 = ggplot(mtcars, aes(x = cyl, y = disp)) + geom_point() + ggtitle('Plot 1') g2 = ggplot(mtcars, aes(x = hp, y = wt)) + geom_point() + ggtitle('Plot 2') ((g1 / plot_spacer()) | g2) + plot_layout(ncol = 2)
Created on 2023-01-08 with reprex v22.214.171.12400
Unfortunately I am unable to use patchwork as one of my graphs is not a ggplot graph. Thank you anyway!
you can nest plot_grid's
library(cowplot) library(ggplot2) g1 <- ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() plot_grid( plot_grid(NULL, g1, ncol = 1, nrow = 2, rel_heights = c(1, 2) ), g1, nrow = 1, ncol = 2 )
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.