Help understanding grid clipping

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?

Mask is for SVG work, I think. If you are going to be doing a lot with {grid} get RGraphics Third Ed. by Paul Murrell.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.