I am attempting to combine three plots into three panels for one figure. Since the three panels share the same data on the x-axis, I would like to remove the x-axis and labels for plots 1 and 2. However, I have encountered an issue where the plot region for plots 1 and 2 is much larger than that for plot 3. How can I fix this?
library(ggplot2)
library(ggpubr)
# Generate synthetic data
set.seed(123)
df1 <- data.frame(x = 1:10, y = rnorm(10))
df2 <- data.frame(x = 1:10, y = rnorm(10))
df3 <- data.frame(x = 1:10, y = rnorm(10))
# Create plots
p1 <- ggplot(df1, aes(x, y)) + geom_point() + labs(title = "Plot 1")
p2 <- ggplot(df2, aes(x, y)) + geom_point() + labs(title = "Plot 2")
p3 <- ggplot(df3, aes(x, y)) + geom_point() + labs(title = "Plot 3")
# Arrange plots using ggarrange
ggarrange(
p1 + rremove(c("x.text")) + rremove("xlab"),
p2 + rremove("x.text") + rremove("xlab"),
p3,
labels = c("A", "B", "C"),
common.legend = TRUE,
legend = "bottom",
nrow = 3
)