diff --git a/NEWS.md b/NEWS.md
index 36daf25177..363a20cc28 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -333,6 +333,8 @@
to retrieve the class via constructor functions (@teunbrand).
* (internal) The ViewScale class has a `make_fixed_copy()` method to permit
copying trained position scales (#3441).
+* `draw_key_rect()` replaces a `NA` fill by the `colour` aesthetic and
+ `draw_key_polygon()` has 0 linewidth as internal default (@teunbrand, #5385).
* Improved consistency of curve direction in `geom_curve()` (@teunbrand, #5069)
* `linetype = NA` is now interpreted to mean 'no line' instead of raising errors
(@teunbrand, #6269).
diff --git a/R/geom-raster.R b/R/geom-raster.R
index 3e3c58975b..819692cea5 100644
--- a/R/geom-raster.R
+++ b/R/geom-raster.R
@@ -127,5 +127,5 @@ GeomRaster <- ggproto("GeomRaster", Geom,
default.units = "native", interpolate = interpolate
)
},
- draw_key = draw_key_rect
+ draw_key = draw_key_polygon
)
diff --git a/R/legend-draw.R b/R/legend-draw.R
index 6e0996886f..04276dd471 100644
--- a/R/legend-draw.R
+++ b/R/legend-draw.R
@@ -54,20 +54,18 @@ draw_key_abline <- function(data, params, size) {
#' @export
#' @rdname draw_key
draw_key_rect <- function(data, params, size) {
+ colour <- if (is.na(data$fill %||% NA)) data$colour
rectGrob(gp = gg_par(
col = NA,
- fill = fill_alpha(data$fill %||% data$colour %||% "grey20", data$alpha),
+ fill = fill_alpha(colour %||% "grey20", data$alpha),
lty = data$linetype %||% 1
))
}
#' @export
#' @rdname draw_key
draw_key_polygon <- function(data, params, size) {
- if (is.null(data$linewidth)) {
- data$linewidth <- 0.5
- }
- lwd <- data$linewidth
+ lwd <- data$linewidth %||% 0
grob <- rectGrob(
width = unit(1, "npc") - unit(lwd, "mm"),
diff --git a/tests/testthat/_snaps/draw-key/time-series-and-polygon-key-glyphs.svg b/tests/testthat/_snaps/draw-key/time-series-and-polygon-key-glyphs.svg
index 90a5b755d2..5e3b176475 100644
--- a/tests/testthat/_snaps/draw-key/time-series-and-polygon-key-glyphs.svg
+++ b/tests/testthat/_snaps/draw-key/time-series-and-polygon-key-glyphs.svg
@@ -59,11 +59,11 @@
z
-
+
-
+
-
+
a
b
c
diff --git a/tests/testthat/_snaps/geom-raster/discrete-positions.svg b/tests/testthat/_snaps/geom-raster/discrete-positions.svg
index ee3e5a1491..5aca7daef6 100644
--- a/tests/testthat/_snaps/geom-raster/discrete-positions.svg
+++ b/tests/testthat/_snaps/geom-raster/discrete-positions.svg
@@ -44,13 +44,13 @@
interaction(x, y)
-
+
-
+
-
+
-
+
A.C
B.C
A.D
diff --git a/tests/testthat/_snaps/geom-raster/irregular-categorical.svg b/tests/testthat/_snaps/geom-raster/irregular-categorical.svg
index 68dda93cfe..dc12288875 100644
--- a/tests/testthat/_snaps/geom-raster/irregular-categorical.svg
+++ b/tests/testthat/_snaps/geom-raster/irregular-categorical.svg
@@ -56,11 +56,11 @@
factor(col)
-
+
-
+
-
+
0
1
NA
diff --git a/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg b/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg
index 9a3ee13ab3..ee53464264 100644
--- a/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg
+++ b/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg
@@ -62,13 +62,13 @@
fill
-
+
-
+
-
+
-
+
A
B
C
diff --git a/tests/testthat/_snaps/legend-draw/all-legend-keys.svg b/tests/testthat/_snaps/legend-draw/all-legend-keys.svg
index c1ea77a335..e535bebe99 100644
--- a/tests/testthat/_snaps/legend-draw/all-legend-keys.svg
+++ b/tests/testthat/_snaps/legend-draw/all-legend-keys.svg
@@ -23,7 +23,7 @@
abline
rect
-
+
polygon
blank