Skip to content

Could functionality be provided to easily retrieve plot height and plot width neatly? #6367

Closed
1 of 1 issue completed
@davidhodge931

Description

@davidhodge931

Awesome new feature re theme panel.widths and panel.heights!

Could ggplot2 provide get_plot_height and get_plot_width functions to support saving plots where the panel.widths and panel.heights have been set.

Basically, it'd be super useful, if I could do something like this:

library(tidyverse)
library(palmerpenguins)

p <- penguins |>
  drop_na(sex) |>
  ggplot() +
  geom_point(
    aes(x = bill_depth_mm,
        y = body_mass_g,
        colour = species),
  ) +
  theme(panel.widths = rep(unit(50, "mm"), times = 100)) +
  theme(panel.heights = rep(unit(50, "mm"), times = 100))

ggsave(
  plot = p, 
  filename = "temp.png",
  height = get_plot_height(p), 
  width = get_plot_width(p), 
)

Sub-issues

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