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

Partial margins #6116

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Partial margins #6116

wants to merge 8 commits into from

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6115.

Briefly it allows NA-units in margin() that get back-filled from parent elements. The function part_margin() is a margin() wrapper that by default has NA-units.

A demonstration. Note no margins except bottom:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  theme(plot.background = element_rect(linetype = 2, colour = "black", fill = NA))

p + 
  theme(plot.margin = margin(b = 2, unit = "cm")) +
  ggtitle("`margin()`")

Note natural margins are preserved, except bottom:

p + 
  theme(plot.margin = part_margin(b = 2, unit = "cm")) +
  ggtitle("`part_margin()`")

Created on 2024-09-19 with reprex v2.1.1

@davidhodge931
Copy link

Great work, @teunbrand

I think it might be helpful for users, if this was named with a margin prefix? This would organise the two functions, so that auto-complete would allow users to easily use the normal one - or switch to the partial one.

So margin_part (or margin_partial)

@teunbrand
Copy link
Collaborator Author

Thanks David, I like this suggestion :)

@arnaudgallou
Copy link

Thanks for considering my FR. Looking forward to seeing this implemented.
Just wanted to let you know the NEWS file references the wrong issue ID (6155 when it should be 6115).

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

Successfully merging this pull request may close these issues.

Consider handling/setting margin()'s default values based on the theme being used
3 participants