I want to display related ggplots together, with axes 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)
Is there a way to prevent this happening?
This is a follow on to a similar question about removing the axis labels asked here. I'm aware I can fudge a fix by changing the height and position in the call to ggdraw, but I'd like a fix that works on the ggplots. As with the previous question, I imagine this is a common problem, but haven't been able to find a solution out there.
theme(axis.text = element_blank())