Skip to content

Commit ee4600c

Browse files
authored
avoid replication of aesthetics across hex bins (#5045)
1 parent a3e79d7 commit ee4600c

File tree

5 files changed

+184
-182
lines changed

5 files changed

+184
-182
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* Fixed a regression in `geom_hex()` where aesthetics were replicated across
4+
bins (@thomasp85, #5037 and #5044)
35
* Fixed spurious warning when `weight` aesthetic was used in `stat_smooth()`
46
(@teunbrand based on @clauswilke's suggestion, #5053).
57
* The `lwd` alias now correctly replaced by `linewidth` instead of `size`

R/geom-hex.r

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ GeomHex <- ggproto("GeomHex", Geom,
8080

8181
n <- nrow(data)
8282

83-
data <- data[rep(seq_len(n), each = 6), ]
84-
data$x <- rep.int(hexC$x, n) + data$x
85-
data$y <- rep.int(hexC$y, n) + data$y
83+
hexdata <- data[rep(seq_len(n), each = 6), c("x", "y")]
84+
hexdata$x <- rep.int(hexC$x, n) + hexdata$x
85+
hexdata$y <- rep.int(hexC$y, n) + hexdata$y
8686

87-
coords <- coord$transform(data, panel_params)
87+
coords <- coord$transform(hexdata, panel_params)
8888

8989
ggname("geom_hex", polygonGrob(
9090
coords$x, coords$y,
9191
gp = gpar(
92-
col = coords$colour,
93-
fill = alpha(coords$fill, coords$alpha),
94-
lwd = coords$linewidth * .pt,
95-
lty = coords$linetype,
92+
col = data$colour,
93+
fill = alpha(data$fill, data$alpha),
94+
lwd = data$linewidth * .pt,
95+
lty = data$linetype,
9696
lineend = lineend,
9797
linejoin = linejoin,
9898
linemitre = linemitre

0 commit comments

Comments
 (0)