From 0295d80f1a3a32783230e13d7709750bdb840ecf Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 28 Mar 2024 16:51:34 +0100 Subject: [PATCH 1/2] `draw_key_polygon()` uses actual linewidth --- R/legend-draw.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/R/legend-draw.R b/R/legend-draw.R index f1de0b80e5..9cb1b36e1a 100644 --- a/R/legend-draw.R +++ b/R/legend-draw.R @@ -74,9 +74,9 @@ draw_key_polygon <- function(data, params, size) { data$linewidth <- 0.5 } - lwd <- min(data$linewidth, min(size) / 4) + lwd <- data$linewidth - rectGrob( + grob <- rectGrob( width = unit(1, "npc") - unit(lwd, "mm"), height = unit(1, "npc") - unit(lwd, "mm"), gp = gpar( @@ -87,6 +87,12 @@ draw_key_polygon <- function(data, params, size) { linejoin = params$linejoin %||% "mitre", lineend = params$lineend %||% "butt" )) + + # Magic number is 5 because we convert mm to cm (divide by 10) but we + # draw two lines in each direction (times 2) + attr(grob, "width") <- lwd / 5 + attr(grob, "height") <- lwd / 5 + grob } #' @export From 7b254b09b012d262f307d79915482fb489f03a67 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 28 Mar 2024 16:54:50 +0100 Subject: [PATCH 2/2] add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index a96a2e4b02..b72a8ebc65 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # ggplot2 (development version) +* The size of the `draw_key_polygon()` glyph now reflects the `linewidth` + aesthetic (#4852). * `coord_map()` and `coord_polar()` throw informative warnings when used with the guide system (#5707). * When passing a function to `stat_contour(breaks)`, that function is used to