Skip to content

Commit 89b829d

Browse files
authored
Fix linewidth of draw_key_polygon() (#5815)
* `draw_key_polygon()` uses actual linewidth * add news bullet
1 parent 9c4ac34 commit 89b829d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* The size of the `draw_key_polygon()` glyph now reflects the `linewidth`
4+
aesthetic (#4852).
35
* New function `complete_theme()` to replicate how themes are handled during
46
plot building (#5801).
57
* Special getter and setter functions have been renamed for consistency, allowing

R/legend-draw.R

+8-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ draw_key_polygon <- function(data, params, size) {
7171
data$linewidth <- 0.5
7272
}
7373

74-
lwd <- min(data$linewidth, min(size) / 4)
74+
lwd <- data$linewidth
7575

76-
rectGrob(
76+
grob <- rectGrob(
7777
width = unit(1, "npc") - unit(lwd, "mm"),
7878
height = unit(1, "npc") - unit(lwd, "mm"),
7979
gp = ggpar(
@@ -84,6 +84,12 @@ draw_key_polygon <- function(data, params, size) {
8484
linejoin = params$linejoin %||% "mitre",
8585
lineend = params$lineend %||% "butt"
8686
))
87+
88+
# Magic number is 5 because we convert mm to cm (divide by 10) but we
89+
# draw two lines in each direction (times 2)
90+
attr(grob, "width") <- lwd / 5
91+
attr(grob, "height") <- lwd / 5
92+
grob
8793
}
8894

8995
#' @export

0 commit comments

Comments
 (0)