Skip to content

Commit 6dd2836

Browse files
committed
Fix calculation of theme defaults
**Issue** At plot time, the calculation of theme elements always fell back to the default theme. As a consequence, the default theme would leak into complete themes where some of the elements were unspecified. **Solution** Be more specific when calculating the theme defaults. **Clean Up** `theme_void` was insufficiently specified. The solution exposed missing elements that had to be specified. Fixes #2058 Fixes #2079
1 parent 619d01c commit 6dd2836

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060

6161
* `ggproto()` produces objects with class `c("ggproto", "gg")`. This was added so that when layers, scales, or other ggproto objects are added together, an informative error message is raised (@jrnold, #2056).
6262

63+
* Fixed bug where a new complete `theme` may fail to override all elements of the default `theme`.
64+
(@has2k1, #2058, #2079)
6365

6466
### sf
6567

R/theme-defaults.r

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,12 @@ theme_void <- function(base_size = 11, base_family = "",
388388
),
389389
axis.text = element_blank(),
390390
axis.title = element_blank(),
391+
axis.ticks.length = unit(0, "pt"),
392+
legend.position = "right",
391393
legend.text = element_text(size = rel(0.8)),
392394
legend.title = element_text(hjust = 0),
393395
strip.text = element_text(size = rel(0.8)),
396+
panel.ontop = FALSE,
394397
plot.margin = unit(c(0, 0, 0, 0), "lines"),
395398

396399
complete = TRUE

R/theme.r

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,14 @@ theme <- function(line,
380380

381381
# Combine plot defaults with current theme to get complete theme for a plot
382382
plot_theme <- function(x) {
383-
defaults(x$theme, theme_get())
383+
complete <- attr(x$theme, "complete")
384+
if (is.null(complete)) {
385+
theme_get()
386+
} else if (complete) {
387+
x$theme
388+
} else {
389+
defaults(x$theme, theme_get())
390+
}
384391
}
385392

386393
#' Modify properties of an element in a theme object

0 commit comments

Comments
 (0)