Partial margins
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
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)
Thanks David, I like this suggestion :)
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).
margin_auto() that behaves like CSS
I like this idea