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

How to add space around the nesting lines in guide_axis_nested #132

Closed
mlell opened this issue Nov 2, 2023 · 2 comments
Closed

How to add space around the nesting lines in guide_axis_nested #132

mlell opened this issue Nov 2, 2023 · 2 comments

Comments

@mlell
Copy link

mlell commented Nov 2, 2023

Thank you for this package which solves an issue I have been suffering from for years! It is almost perfect, despite one thing:

library(tibble)
library(dplyr)
library(ggplot2)
tibble(loc = rep(c("München", "Berlin", "Alteglofsheim"), 2), 
       year = c("2020","2021","2020","2021", "2020", "2021"), 
       y = runif(6,0,1)) %>% mutate(x = paste0(year,".",loc)) %>% 
  ggplot() + aes(x = x, y=y) + geom_col() + 
    scale_x_discrete(guide = ggh4x::guide_axis_nested(inv=TRUE,angle=90))

The text is very close to the nesting line. How can I add some space there?

As a workaround, I could just add some space before the city names, however this only works if the text is vertical. Is there a more canonical way, like a theme() setting? I only found ggh4x.axis.nesttext.x/y which as an element_text() object does not have a margin setting or similar.

@teunbrand
Copy link
Owner

Every element_text() has its own margin, so you could use theme(axis.text.x.bottom = element_text(margin = margin(t = 2.2, b = 10))) to space the nesting line further from the rotated text.

@mlell
Copy link
Author

mlell commented Nov 2, 2023

Ah, yes I did not think of modifying the text instead of the line. Thanks!

@mlell mlell closed this as completed Nov 2, 2023
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

2 participants