Skip to content

Commit 4eaa98b

Browse files
authored
Background for theme_void() and theme_minimal() (#6345)
* set paper backgrounds * accept invisible rectangles * follow conventional inheritance to satisfy test * redocument
1 parent 80d5406 commit 4eaa98b

8 files changed

+20
-4
lines changed

R/theme-defaults.R

+13-3
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ theme_minimal <- function(base_size = 11, base_family = "",
472472
panel.background = element_blank(),
473473
panel.border = element_blank(),
474474
strip.background = element_blank(),
475-
plot.background = element_blank(),
475+
plot.background = element_rect(fill = paper, colour = NA),
476476

477477
complete = TRUE
478478
)
@@ -517,13 +517,16 @@ theme_void <- function(base_size = 11, base_family = "",
517517
header_family = NULL,
518518
base_line_size = base_size / 22,
519519
base_rect_size = base_size / 22,
520-
ink = "black", paper = "white") {
520+
ink = "black", paper = alpha(ink, 0)) {
521521
half_line <- base_size / 2
522522

523523
# Only keep indispensable text: legend and plot titles
524524
t <- theme(
525525
line = element_blank(),
526-
rect = element_blank(),
526+
rect = element_rect(
527+
fill = paper, colour = NA, linewidth = 0, linetype = 1,
528+
inherit.blank = FALSE
529+
),
527530
polygon = element_blank(),
528531
point = element_blank(),
529532
text = element_text(
@@ -555,12 +558,18 @@ theme_void <- function(base_size = 11, base_family = "",
555558
legend.box.margin = rel(0),
556559
legend.box.spacing = unit(0.2, "cm"),
557560
legend.ticks.length = rel(0.2),
561+
legend.background = element_blank(),
562+
legend.frame = element_blank(),
563+
legend.box.background = element_blank(),
558564
strip.clip = "on",
559565
strip.text = element_text(size = rel(0.8)),
560566
strip.switch.pad.grid = rel(0.5),
561567
strip.switch.pad.wrap = rel(0.5),
568+
strip.background = element_blank(),
562569
panel.ontop = FALSE,
563570
panel.spacing = NULL,
571+
panel.background = element_blank(),
572+
panel.border = element_blank(),
564573
plot.margin = rel(0),
565574
plot.title = element_text(
566575
size = rel(1.2),
@@ -583,6 +592,7 @@ theme_void <- function(base_size = 11, base_family = "",
583592
hjust = 0.5, vjust = 0.5
584593
),
585594
plot.tag.position = 'topleft',
595+
plot.background = element_rect(),
586596

587597
complete = TRUE
588598
)

man/ggtheme.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/geom-polygon/open-and-closed-munched-polygons.svg

+1
Loading

tests/testthat/_snaps/guides/guide-custom-with-void-theme.svg

+1
Loading

tests/testthat/_snaps/theme/theme-minimal-large.svg

+1
Loading

tests/testthat/_snaps/theme/theme-minimal.svg

+1
Loading

tests/testthat/_snaps/theme/theme-void-large.svg

+1
Loading

tests/testthat/_snaps/theme/theme-void.svg

+1
Loading

0 commit comments

Comments
 (0)