trevorld / ggpattern

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

clip/mask holed polygons with R 4.1 alpha masks instead of clipping paths? #69

Closed trevorld closed 2 years ago

trevorld commented 2 years ago
trevorld commented 2 years ago

After some light testing it seems "alpha mask" clipping may be more robust than "clipping path" clipping for pathGrob(). Will write gridpattern::maskGrob() and then use that instead of gridpattern::clippingPathGrob() to clip holed polygons (pathGrob()).

trevorld commented 2 years ago

E-mail from Prof. Murrell implies that if we wanted to keep using the "clipping path" feature than whenever {sf} converts an sf object to a pathGrob that uses an "evenodd" rule (or we receive an "evenodd" rule from geom_polygon_pattern()) then we'd need detect which rule it uses and if it is the "evenodd" rule we'd need to explicitly use the new R4.2 function as.path() and explicitly set its rule argument to "evenodd" (if it uses the "winding" rule we don't need to use as.path() [but could if we wanted to]). This is because the R 4.1 clipping path function considers all clipping paths to follow the "winding" rule by default (even if it is a pathGrob() with an "evenodd" rule).

https://stattech.wordpress.fos.auckland.ac.nz/2021/11/16/2021-03-stroking-and-filling-paths-in-r-graphics/