Skip to content

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5801.

It introduces a new function, complete_theme() that wraps the internal plot_theme() function with some additional I/O checks.

Reprex from the issue:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
p <- ggplot(mpg, aes(displ, hwy, colour = factor(cyl))) + 
  geom_point() +
  theme(axis.line = element_line())
build <- ggplot_build(p)

guides <- build$plot$guides
my_theme <- complete_theme(build$plot$theme)

guides$assemble(my_theme + theme(legend.direction = "horizontal"))$right
#> TableGrob (5 x 5) "guide-box": 2 grobs
#>   z     cells                  name           grob
#> 1 1 (3-3,3-3)                guides gtable[layout]
#> 2 0 (2-4,2-4) legend.box.background zeroGrob[NULL]
guides$assemble(my_theme + theme(legend.direction = "vertical"))$right
#> TableGrob (5 x 5) "guide-box": 2 grobs
#>   z     cells                  name           grob
#> 1 1 (3-3,3-3)                guides gtable[layout]
#> 2 0 (2-4,2-4) legend.box.background zeroGrob[NULL]

Created on 2024-03-25 with reprex v2.1.0

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit ecf5f40 into tidyverse:main May 20, 2024
@teunbrand teunbrand deleted the complete_theme branch May 20, 2024 13:15
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.

Feature request: export plot_theme()

2 participants