Skip to content

Allow use of rep() within ggplot2::margin() #6659

@cararthompson

Description

@cararthompson

In the previous version, I believe it was possible to use rep() within ggplot2::margin() to set margins to all be the same value. This seems to no longer be possible. Is this change deliberate? It was handy when wanting to create margins based on the base text size argument of a custom theme function, for example (e.g plot.margin = margin(rep(base_text_size * 1.5, 4)))

# This plot has no margins
babynames::babynames |>
  dplyr::filter(name %in% c("Mary", "Hannah"), sex == "F") |>
  ggplot(aes(x = year, y = n, group = name, color = name)) +
  geom_line() +
  theme(plot.margin = margin(rep(20, 4)))

# This plot does have margins
babynames::babynames |>
  dplyr::filter(name %in% c("Mary", "Hannah"), sex == "F") |>
  ggplot(aes(x = year, y = n, group = name, color = name)) +
  geom_line() +
  theme(plot.margin = margin(20, 20, 20, 20))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions