if (capabilities("png") && require("grid")) {
clippee <- patternGrob("circle", gp = gpar(col = "black", fill = "yellow"),
spacing = 0.1, density = 0.5)
angle <- seq(2 * pi / 4, by = 2 * pi / 6, length.out = 7)
x_hex_outer <- 0.5 + 0.5 * cos(angle)
y_hex_outer <- 0.5 + 0.5 * sin(angle)
x_hex_inner <- 0.5 + 0.25 * cos(rev(angle))
y_hex_inner <- 0.5 + 0.25 * sin(rev(angle))
clipper <- grid::pathGrob(x = c(x_hex_outer, x_hex_inner),
y = c(y_hex_outer, y_hex_inner),
id = rep(1:2, each = 7),
rule = "evenodd")
clipped <- clippingPathGrob(clippee, clipper, use_R4.1_clipping = FALSE)
grid.newpage()
grid.draw(clipped)
}
Run the code above in your browser using DataLab