Skip to content

Commit 977e051

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 tidyverse#2058 Fixes tidyverse#2079
1 parent fa8004e commit 977e051

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

R/theme-defaults.r

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,12 @@ theme_void <- function(base_size = 11, base_family = "") {
336336
),
337337
axis.text = element_blank(),
338338
axis.title = element_blank(),
339+
axis.ticks.length = unit(0, "pt"),
340+
legend.position = "right",
339341
legend.text = element_text(size = rel(0.8)),
340342
legend.title = element_text(hjust = 0),
341343
strip.text = element_text(size = rel(0.8)),
344+
panel.ontop = FALSE,
342345
plot.margin = unit(c(0, 0, 0, 0), "lines"),
343346

344347
complete = TRUE

R/theme.r

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,13 @@ 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+
if (is.null(attr(x$theme, "complete"))) {
384+
theme_get()
385+
} else if (attr(x$theme, "complete")) {
386+
x$theme
387+
} else {
388+
defaults(x$theme, theme_get())
389+
}
384390
}
385391

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

0 commit comments

Comments
 (0)