Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* The size of the `draw_key_polygon()` glyph now reflects the `linewidth`
aesthetic (#4852).
* New function `complete_theme()` to replicate how themes are handled during
plot building (#5801).
* Special getter and setter functions have been renamed for consistency, allowing
Expand Down
10 changes: 8 additions & 2 deletions R/legend-draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,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 = ggpar(
Expand All @@ -84,6 +84,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
Expand Down