grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
211 stars 7 forks source link

Support type = "polypath" #159

Closed grantmcdermott closed 3 weeks ago

grantmcdermott commented 3 weeks ago

Closes #158.

grantmcdermott commented 3 weeks ago

Aside: This should also enable consistent tinyplot support for spatial objects, since polypath is what sf, geos, and co. use under the hood for their plot methods.

pkgload::load_all("~/Documents/Projects/tinyplot/")
library(sf)

nc_shapefile = system.file("shape/nc.shp", package = "sf")
nc = st_read(nc_shapefile)

get_geom = function(x) {
    m = Map(as.data.frame, Map(`[[`, Map(`[[`, nc$geometry, 1), 1))
    for (i in seq_along(m)) m[[i]][["idx"]] = i
    m = do.call("rbind", m)
    names(m) = c("lon", "lat", "idx")
    m
}

ncg = get_geom(nc)
plt(
    lat ~ lon | factor(idx), ncg,
    type = "polypath",
    fill = 0.8, col = "white",
    legend = FALSE
)

Created on 2024-07-06 with reprex v2.1.0