I'm writing a ggplot extension and trying to understand how to clip to an area using grid graphics.
# in my draw_panel function
mask <- grid::rectGrob(default.units = "native",
gp = gpar(fill = rgb(0,0,0,1)))
vp <- viewport(x = mean(x_rng), y = mean(y_rng), width = diff(x_rng),
height = diff(y_rng), default.units = "native",
mask = mask)
mygrob <- grid::editGrob(mygrob, vp = vp)
The above works fine, but it requires R 4.2.0 or later to use mask
, and I am only using it to clip to the panel area. But if I replace mask = mask
with clip = mask
, clipping doesn't happen. Does anyone understand how clipping works in grid, or can point me to a good reference?