I would like to align vertical plot from row 1 and plot from row 2. It didn't matter how hard I try, but it did not let me align.
Any ideas?
library(dplyr)
library(forcats)
library(ggplot2)
library(cowplot)
city_mpg <- mpg %>%
mutate(class = fct_lump(class, 4, other_level = "other")) %>%
group_by(class) %>%
summarize(
mean_mpg = mean(cty),
count = n()
) %>% mutate(
class = fct_reorder(class, count)
)
p1 <- ggplot(city_mpg, aes(class, count)) +
geom_col() +
ylim(0, 65) +
coord_flip()
p2 <- ggplot(city_mpg, aes(mean_mpg, count)) +
geom_point()
p3 <- ggplot(mtcars, aes(wt, mpg)) +
geom_point()
first <- plot_grid(p1, p2, align = 'h', axis = 'l',rel_widths = c(2,1))
second <- plot_grid(p3)
plot_grid(first, second,ncol = 1, align = 'v', axis = 'l',rel_heights = c(2,1))