trevorld / ggpattern

ggplot geoms with pattern fills
https://trevorldavis.com/R/ggpattern/dev/
Other
359 stars 18 forks source link

Patterns filling holes when using recent versions of {ragg} #68

Closed trevorld closed 2 years ago

trevorld commented 2 years ago

Patterns may fill holes when using recent versions of {ragg} and R 4.1 clipping is enabled.

This affects geom_sf_pattern() and geom_polygon_pattern() when they have holes.

library("ggplot2")
library("ggpattern")
library("ragg")

this_sf <- structure(list(id = 1L,
    geometry = structure(list(structure(list(
                                             structure(c(0, 4, 4, 0, 0, 0, 0, 4, 4, 0), .Dim = c(5L, 2L)),
                                             structure(c(1, 2, 2, 1, 1, 1, 1, 2, 2, 1), .Dim = c(5L, 2L))),
                                        class = c("XY", "POLYGON", "sfg"))),
                         n_empty = 0L,
                         crs = structure(list(
                                              input = NA_character_,
                                              wkt = NA_character_),
                                         class = "crs"),
                         class = c("sfc_POLYGON", "sfc"),
                         precision = 0,
                         bbox = structure(c(xmin = 0, ymin = 0, xmax = 4, ymax = 4),
                                          class = "bbox"))),
                   class = c("sf", "data.frame"),
                   sf_column = "geometry", row.names = 1L)

p <- ggplot(this_sf) +
        geom_sf_pattern(aes(geometry = geometry), fill = 'lightblue')

ragg::agg_png("sf_hole_ragg.png")
options(ggpattern_use_R4.1_clipping = TRUE)
plot(p)
dev.off()

sf_hole_ragg

Workarounds:

ragg::agg_png("sf_hole_ragg_no_clipping.png")
options(ggpattern_use_R4.1_clipping = FALSE)
plot(p)
dev.off()

grDevices::png("sf_hole_cairo.png", type = "cairo")
options(ggpattern_use_R4.1_clipping = TRUE)
plot(p)
dev.off()

sf_hole_cairo