ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

Partial margins

Open teunbrand opened this issue 1 year ago • 3 comments

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

teunbrand avatar Sep 19 '24 13:09 teunbrand