stat_unpack_polygon() expands compact list-column coordinates
stored as numeric vectors in x and y columns into long format
suitable for geom_polygon() and geom_shape().
Usage
stat_unpack_polygon(
mapping = NULL,
data = NULL,
geom = "polygon",
position = "identity",
na.rm = TRUE,
show.legend = NA,
inherit.aes = TRUE,
...
)Details
This stat is designed for memory-efficient storage of polygon
coordinates where each polygon occupies a single row, with x
and y columns containing numeric vectors of coordinates.
It unpacks these into the long format expected by ggplot2
polygon geoms during the statistical transformation layer.
The stat requires a grouping column (typically id or similar)
to distinguish between separate polygons when multiple polygons
are present in a single dataset. If no grouping is provided, each
row is treated as a separate polygon.
Aesthetics
stat_unpack_polygon() requires the following aesthetics:
x— numeric vector (list-column) or numeric valuesy— numeric vector (list-column) or numeric values
It can accept any aesthetics supported by geom_polygon() or
geom_shape(), such as fill, colour, size, alpha, linetype.
See also
Other ggplot2 customizations:
geom_diagonal_wide_arc(),
splicejam-extensions,
to_basic.GeomShape()
Examples
# Create compact polygon data with list-column coordinates
polygon_data <- data.frame(
id = c(1, 2),
x = list(c(0, 1, 1, 0), c(2, 3, 3.5, 2)),
y = list(c(0, 0, 1, 1), c(0, 0, 1.5, 1)),
fill = c("red", "blue")
)
# Plot with stat_unpack_polygon
# ggplot(polygon_data, aes(x = x, y = y, fill = fill)) +
# geom_polygon(stat = "unpack_polygon") +
# coord_fixed()