Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function for completing themes #5804

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

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

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