Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linewidth of draw_key_polygon() #5815

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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,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
Expand Down
10 changes: 8 additions & 2 deletions R/legend-draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
Loading