Skip to content

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6367.

It implements widthDetails() and heightDetails() methods, that essentially convert a plot to a gtable and use the gtable method.

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

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point()

widthDetails(p)
#> [1] sum(5.5points, 0points, 0cm, 0points, 1null, 1null, 0cm, 0cm, 0points, 0cm, 0points, 5.5points, 0cm, 1null, 0.447737823439878cm, 0null, max(0points, -0.0966514459665145cm), 0.0966514459665145cm)

heightDetails(p)
#> [1] sum(5.5points, 0points, 0cm, 0cm, 0cm, 0points, 0cm, 0cm, 1null, 1null, 0points, 0cm, 0cm, 0points, 5.5points, 0.0966514459665145cm, max(0points, -0.0966514459665145cm), 0null, 0.394821156773212cm, 1null, 0cm)

Created on 2025-03-21 with reprex v2.1.1

@thomasp85
Copy link
Member

I'm a bit hesitant on this since these generics are explicitly intended for grobs, which ggplot and ggplot_build objects are not

@thomasp85 thomasp85 closed this Mar 25, 2025
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.

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

2 participants