Skip to content

Commit 8d6ffd0

Browse files
committed
geom_polygon: make sure id is a factor/numeric
polygonGrob requires that `id` is numeric, but the value passed to it, munched$group, was sometimes a character vector. Converting to a factor ensures that it's numeric.
1 parent 9395803 commit 8d6ffd0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

R/geom-polygon.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ GeomPolygon <- proto(Geom, {
5858
draw <- function(., data, scales, coordinates, ...) {
5959
n <- nrow(data)
6060
if (n == 1) return()
61+
62+
# Check if group is numeric, to make polygonGrob happy (factors are numeric,
63+
# but is.numeric() will report FALSE because it actually checks something else)
64+
if (mode(data$group) != "numeric")
65+
data$group <- factor(data$group)
6166

6267
munched <- coord_munch(coordinates, data, scales)
6368
# Sort by group to make sure that colors, fill, etc. come in same order

R/stat-contour.r

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@ contour_lines <- function(data, breaks, complete = FALSE) {
111111
xs <- unlist(lapply(cl, "[[", "x"), use.names = FALSE)
112112
ys <- unlist(lapply(cl, "[[", "y"), use.names = FALSE)
113113
pieces <- rep(seq_along(cl), lengths)
114-
114+
# Add leading zeros so that groups can be properly sorted later
115+
groups <- paste(data$group[1], sprintf("%03d", pieces), sep = "-")
116+
115117
data.frame(
116118
level = rep(levels, lengths),
117119
x = xs,
118120
y = ys,
119121
piece = pieces,
120-
group = paste(data$group[1], pieces, sep = "-")
122+
group = groups
121123
)
122124
}
123125

0 commit comments

Comments
 (0)