Skip to content

Commit a96e664

Browse files
authored
Key background inherits panel background (#5551)
* legend.key inherits from panel.background * default themes don't set legend.key * accept slightly darker keys in tests * Add news bullet * accept stray snapshot
1 parent 5f518d0 commit a96e664

10 files changed

+24
-27
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ggplot2 (development version)
22

3+
* The `legend.key` theme element is set to inherit from the `panel.background`
4+
theme element. The default themes no longer set the `legend.key` element.
5+
This causes a visual change with the default `theme_gray()` (#5549).
6+
37
* Lines where `linewidth = NA` are now dropped in `geom_sf()` (#5204).
48

59
* New `guide_axis_logticks()` can be used to draw logarithmic tick marks as

R/theme-defaults.R

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ theme_grey <- function(base_size = 11, base_family = "",
172172
legend.spacing.x = NULL,
173173
legend.spacing.y = NULL,
174174
legend.margin = margin(half_line, half_line, half_line, half_line),
175-
legend.key = element_rect(fill = "grey95", colour = NA),
175+
legend.key = NULL,
176176
legend.key.size = unit(1.2, "lines"),
177177
legend.key.height = NULL,
178178
legend.key.width = NULL,
@@ -266,8 +266,6 @@ theme_bw <- function(base_size = 11, base_family = "",
266266
panel.grid.minor = element_line(linewidth = rel(0.5)),
267267
# contour strips to match panel contour
268268
strip.background = element_rect(fill = "grey85", colour = "grey20"),
269-
# match legend key to background
270-
legend.key = element_rect(fill = "white", colour = NA),
271269

272270
complete = TRUE
273271
)
@@ -340,9 +338,6 @@ theme_light <- function(base_size = 11, base_family = "",
340338
# match axes ticks thickness to gridlines and colour to panel border
341339
axis.ticks = element_line(colour = "grey70", linewidth = rel(0.5)),
342340

343-
# match legend key to panel.background
344-
legend.key = element_rect(fill = "white", colour = NA),
345-
346341
# dark strips with light text (inverse contrast compared to theme_grey)
347342
strip.background = element_rect(fill = "grey70", colour = NA),
348343
strip.text = element_text(
@@ -382,9 +377,6 @@ theme_dark <- function(base_size = 11, base_family = "",
382377
# match axes ticks thickness to gridlines
383378
axis.ticks = element_line(colour = "grey20", linewidth = rel(0.5)),
384379

385-
# match legend key to panel.background
386-
legend.key = element_rect(fill = "grey50", colour = NA),
387-
388380
# dark strips with light text (inverse contrast compared to theme_grey)
389381
strip.background = element_rect(fill = "grey15", colour = NA),
390382
strip.text = element_text(
@@ -442,9 +434,6 @@ theme_classic <- function(base_size = 11, base_family = "",
442434
# show axes
443435
axis.line = element_line(colour = "black", linewidth = rel(1)),
444436

445-
# match legend key to panel.background
446-
legend.key = element_blank(),
447-
448437
# simple, black and white strips
449438
strip.background = element_rect(fill = "white", colour = "black", linewidth = rel(2)),
450439
# NB: size is 1 but clipped, it looks like the 0.5 of the axes
@@ -586,7 +575,7 @@ theme_test <- function(base_size = 11, base_family = "",
586575
legend.spacing.x = NULL,
587576
legend.spacing.y = NULL,
588577
legend.margin = margin(0, 0, 0, 0, "cm"),
589-
legend.key = element_rect(fill = "white", colour=NA),
578+
legend.key = NULL,
590579
legend.key.size = unit(1.2, "lines"),
591580
legend.key.height = NULL,
592581
legend.key.width = NULL,

R/theme-elements.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ el_def <- function(class = NULL, inherit = NULL, description = NULL) {
497497
legend.spacing = el_def("unit"),
498498
legend.spacing.x = el_def(c("unit", "rel"), "legend.spacing"),
499499
legend.spacing.y = el_def(c("unit", "rel"), "legend.spacing"),
500-
legend.key = el_def("element_rect", "rect"),
500+
legend.key = el_def("element_rect", "panel.background"),
501501
legend.key.height = el_def(c("unit", "rel"), "legend.key.size"),
502502
legend.key.width = el_def(c("unit", "rel"), "legend.key.size"),
503503
legend.text = el_def("element_text", "text"),

tests/testthat/_snaps/guides/left-aligned-legend-key.svg

Lines changed: 3 additions & 3 deletions
Loading

tests/testthat/_snaps/theme/caption-aligned-to-entire-plot.svg

Lines changed: 3 additions & 3 deletions
Loading

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

Lines changed: 2 additions & 0 deletions
Loading

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

Lines changed: 2 additions & 0 deletions
Loading

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

Lines changed: 2 additions & 2 deletions
Loading

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

Lines changed: 2 additions & 2 deletions
Loading

tests/testthat/_snaps/theme/titles-aligned-to-entire-plot.svg

Lines changed: 3 additions & 3 deletions
Loading

0 commit comments

Comments
 (0)