Skip to content

Commit e70fb93

Browse files
committed
Fix colors for geom_polygon
1 parent 6d8629c commit e70fb93

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

R/geom-polygon.r

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,22 @@ GeomPolygon <- proto(Geom, {
5959
n <- nrow(data)
6060
if (n == 1) return()
6161

62+
munched <- coord_munch(coordinates, data, scales)
63+
64+
# For gpar(), there is one entry per polygon (not one entry per point).
65+
# We'll pull the first value from each group, and assume all these values
66+
# are the same within each group.
67+
first_idx <- !duplicated(munched$group)
68+
first_rows <- munched[first_idx, ]
69+
6270
ggname(.$my_name(), gTree(children = gList(
63-
with(coord_munch(coordinates,data, scales),
64-
polygonGrob(x, y, default.units = "native", id = group,
65-
gp = gpar(col = colour, fill = alpha(fill, alpha),
66-
lwd = size * .pt, lty = linetype)
71+
polygonGrob(munched$x, munched$y, default.units = "native",
72+
id = munched$group,
73+
gp = gpar(
74+
col = first_rows$colour,
75+
fill = alpha(first_rows$fill, first_rows$alpha),
76+
lwd = first_rows$size * .pt,
77+
lty = first_rows$linetype
6778
)
6879
)
6980
)))

0 commit comments

Comments
 (0)