clippingPathGrob: Clip grob using another grob to specify the clipping path

Description Usage Arguments Value Examples

View source: R/clippingPathGrob.R

Description

clippingPathGrob() clips a grob using another grob to specify the clipping path

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
clippingPathGrob(
  clippee,
  clipper,
  use_R4.1_clipping = getOption("ggpattern_use_R4.1_clipping",
    getOption("ggpattern_use_R4.1_features")),
  png_device = NULL,
  res = 72,
  name = NULL,
  gp = gpar(),
  vp = NULL
)

Arguments

clippee

Grob to be clipped

clipper

Grob that defines clipping region

use_R4.1_clipping

If TRUE use the grid clipping path feature introduced in R v4.1.0. If FALSE do a rasterGrob approximation. If NULL try to guess an appropriate choice. Note not all graphic devices support the grid clipping path feature and the grid clipping path feature does not nest.

png_device

“png” graphics device to use if use_R4.1_clipping is FALSE. If NULL (default) will use ragg::agg_png() if the suggested package ragg is available else grDevices::png().

res

Resolution of desired rasterGrob in pixels per inch if use_R4.1_clipping is FALSE.

name

A character identifier.

gp

An object of class "gpar", typically the output from a call to the function gpar. This is basically a list of graphical parameter settings.

vp

A Grid viewport object (or NULL).

Value

A grid grob

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
  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),
                              rule = "evenodd")
    clipped <- clippingPathGrob(clippee, clipper, use_R4.1_clipping = FALSE)
    grid.newpage()
    grid.draw(clipped)
  }

gridpattern documentation built on July 17, 2021, 9:07 a.m.