Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gap between axis label and text if adjacent plot has vertical axis text #285

Open
kotliary opened this issue Dec 1, 2021 · 5 comments
Open

Comments

@kotliary
Copy link

kotliary commented Dec 1, 2021

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)

@kotliary
Copy link
Author

It's the same issue as reported in #272 and #276.

@Generalized
Copy link

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:
obraz

and after the workaround:

final_plot[[1]] <- final_plot[[1]] + theme(axis.title.y = element_text(vjust = -50))
final_plot

obraz

@kotliary
Copy link
Author

kotliary commented May 9, 2022

Good workaround. Thanks!

@thomasp85
Copy link
Owner

@kotliary did the above solve your question or did you mean to expand the plot to fill out the white space?

@kotliary
Copy link
Author

kotliary commented Nov 7, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants