patchwork
patchwork copied to clipboard
Gap between axis label and text if adjacent plot has vertical axis text
Please check the following code. Is there a way to remove this gap ignoring the other plots?
library(tidyverse)
df1 = data.frame(Group = factor(1:10), Value = runif(10))
df2 = data.frame(Group = factor(1:10), Long_label_A = runif(10), Long_label_B = runif(10), Long_label_C = runif(10)) %>%
gather(Label, X, -Group)
p1 = ggplot(df1, aes(Value, Group)) +
geom_col(orientation = "y", position = "identity")
p2 = ggplot(df2, aes(Label, Group, fill = X)) +
geom_tile() +
ylab("") +
theme_void() +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
library(patchwork)
p1 + p2 + plot_layout(nrow = 1, widths = c(0.9, 0.1))

Created on 2021-12-01 by the reprex package (v2.0.0)
It's the same issue as reported in #272 and #276.
I have a similar issue, only horizontally. I found a quick and dirty workaround, maybe it will help someone, as the original positioning of the axis title looks ugly.
Original plot:

and after the workaround:
final_plot[[1]] <- final_plot[[1]] + theme(axis.title.y = element_text(vjust = -50)) final_plot

Good workaround. Thanks!
@kotliary did the above solve your question or did you mean to expand the plot to fill out the white space?
@thomasp85 sorry for missing your question. No, I don't want to expand the plot to fill the white space. I want to move the axis title closer to the axis.
The workaround from @Generalized solved my issue, but the vjust value need to be adjusted manually. It would be nice if the position of axis title can be automatically adjusted by the patchwork.