Is there a way to save or display related ggplots with axes for each plot all the same size, but with some plots displaying the axis tick labels and other plots blanking the axis tick labels? The code below shows two ways I've removed the tick labels, but both resize the plots:
library(tidyverse)
library(cowplot)
tb <- tibble(a = 1:5, b = 1:5)
without_x_title <- ggplot(tb, aes(a,b)) +
geom_point() +
labs(x = "")
without_x_title_labels_1 <- ggplot(tb, aes(a,b)) +
geom_point() +
labs(x = "") +
scale_x_discrete(labels = "")
without_x_title_labels_2 <- ggplot(tb, aes(a,b)) +
geom_point() +
labs(x = "") +
theme(axis.text.x = element_blank())
ggdraw() +
draw_plot(without_x_title, x = 0, y = 0, width = 0.3, height = 1) +
draw_plot(without_x_title_labels_1, x = 0.3, y = 0, width = 0.3, height = 1) +
draw_plot(without_x_title_labels_2, x = 0.6, y = 0, width = 0.3, height = 1)
I can fix this using cowplot::plot_grid or the patchwork package (see here), but I would like a fix that works at the level of the individual ggplots, for example so the axes appear the same size in the RStudio viewer or when I export/save them.
Any help would be greatly appreciated.