Skip to content

Missing elements in theme definitions #3584

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

Closed
clauswilke opened this issue Oct 24, 2019 · 1 comment · Fixed by #3585
Closed

Missing elements in theme definitions #3584

clauswilke opened this issue Oct 24, 2019 · 1 comment · Fixed by #3585

Comments

@clauswilke
Copy link
Member

All themes miss some elements in their definitions (i.e., elements are implicitly set to NULL rather than explicitly set to NULL). I think all themes provided by ggplot2 should explicitly define all elements. This will become more important if we want to allow extensible themes (#2540, #2784), because we'll have to distinguish between elements a theme knows about but wants to be NULL and elements a theme doesn't know about that need to be filled in from the theme defaults. Missing element definitions also have led to unexpected problems in the past, e.g. #2724.

Elements that I notice are missing:

  • In all themes: some of panel.grid, panel.grid.major, panel.grid.minor, panel.grid.major.x, panel.grid.minor.x, panel.grid.major.y, panel.grid.minor.y
  • In theme_void(): Too many to list, including parts of axis.*, legend.*, panel.*, strip.*, plot.background.

As an aside, we should recommend as a general practice to external theme developers that they always start with an existing ggplot2 theme and then just modify the parts they want to change, just like we do in most cases:

ggplot2/R/theme-defaults.r

Lines 247 to 267 in 6f5ffea

# Starts with theme_grey and then modify some parts
theme_grey(
base_size = base_size,
base_family = base_family,
base_line_size = base_line_size,
base_rect_size = base_rect_size
) %+replace%
theme(
# white background and dark border
panel.background = element_rect(fill = "white", colour = NA),
panel.border = element_rect(fill = NA, colour = "grey20"),
# make gridlines dark, same contrast with white as in theme_grey
panel.grid = element_line(colour = "grey92"),
panel.grid.minor = element_line(size = rel(0.5)),
# contour strips to match panel contour
strip.background = element_rect(fill = "grey85", colour = "grey20"),
# match legend key to background
legend.key = element_rect(fill = "white", colour = NA),
complete = TRUE
)

clauswilke added a commit to wilkelab/ggplot2_archive that referenced this issue Oct 25, 2019
clauswilke added a commit that referenced this issue Nov 14, 2019
* explicitly define all theme elements. closes #3584.

* generate and cache all null theme on load
@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 a pull request may close this issue.

1 participant