Skip to content

Explicitly define all theme elements #3585

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

Merged

Conversation

clauswilke
Copy link
Member

@clauswilke clauswilke commented Oct 25, 2019

This PR closes #3584 by making sure every theme explicitly defines every possible theme element. The strategy is to simply set every element that hasn't been defined explicitly to NULL. This can be done programmatically in a few lines of code.

@clauswilke clauswilke requested a review from thomasp85 October 25, 2019 07:05
Comment on lines +653 to 663
theme_all_null <- function() {
# set all elements in the element tree to NULL
elements <- sapply(
names(ggplot_global$element_tree),
function(x) NULL,
simplify = FALSE, USE.NAMES = TRUE
)

args <- c(elements, list(complete = TRUE))
do.call(theme, args)
}
Copy link
Member

Choose a reason for hiding this comment

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

Could we cache this theme as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, will do that tomorrow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I'm also wondering whether this function should be exported, so external package developers can use the same trick, or whether we should rather encourage them to always start with one of the usable ggplot2 themes.

Copy link
Member

Choose a reason for hiding this comment

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

I think it is better to guide them towards modifying an existing theme... They can always base it off theme_void() if they want a clean slate

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. In any case, I think we need a vignette or other document to provide best practices recommendations for themes. I'll probably write something like that when I'm done with the theme reworking.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did a quick check. It looks like all the most popular theme packages already always start from an existing theme. In fact, I couldn't find any example that didn't do this.

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

@clauswilke clauswilke merged commit f0ce285 into tidyverse:master Nov 14, 2019
@clauswilke clauswilke deleted the issue-3584-missing-theme-elements branch November 14, 2019 15:39
@lock
Copy link

lock bot commented May 20, 2020

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

1 similar comment
@lock
Copy link

lock bot commented May 20, 2020

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing elements in theme definitions
2 participants