grid.pattern: Create patterned grobs

Description Usage Arguments Format Details Value See Also Examples

View source: R/grid-pattern.R

Description

grid.pattern() draws patterned shapes onto the graphic device. patternGrob() returns the grid grob objects. names_pattern is a character vector of builtin patterns.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
grid.pattern(
  pattern = "stripe",
  x = c(0, 0, 1, 1),
  y = c(1, 0, 0, 1),
  id = 1L,
  ...,
  legend = FALSE,
  prefix = "pattern_",
  default.units = "npc",
  name = NULL,
  gp = gpar(),
  draw = TRUE,
  vp = NULL
)

names_pattern

patternGrob(
  pattern = "stripe",
  x = c(0, 0, 1, 1),
  y = c(1, 0, 0, 1),
  id = 1L,
  ...,
  legend = FALSE,
  prefix = "pattern_",
  default.units = "npc",
  name = NULL,
  gp = gpar(),
  draw = TRUE,
  vp = NULL
)

Arguments

pattern

Name of pattern. See Details section for a list of supported patterns.

x

A numeric vector or unit object specifying x-locations of the pattern boundary.

y

A numeric vector or unit object specifying y-locations of the pattern boundary.

id

A numeric vector used to separate locations in x, y into multiple boundaries. All locations within the same id belong to the same boundary.

...

Pattern parameters.

legend

Whether this is intended to be drawn in a legend or not.

prefix

Prefix to prepend to the name of each of the pattern parameters in .... For compatibility with ggpattern most underlying functions assume parameters beginning with pattern_.

default.units

A string indicating the default units to use if x or y are only given as numeric vectors.

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.

draw

A logical value indicating whether graphics output should be produced.

vp

A Grid viewport object (or NULL).

Format

An object of class character of length 17.

Details

Here is a list of the various patterns supported:

ambient

Noise array patterns onto the graphic device powered by the ambient package. See grid.pattern_ambient() for more information.

circle

Circle geometry patterns. See grid.pattern_circle() for more information.

crosshatch

Crosshatch geometry patterns. See grid.pattern_crosshatch() for more information.

gradient

Gradient array/geometry patterns. See grid.pattern_gradient() for more information.

image

Image array patterns. See grid.pattern_image() for more information.

magick

imagemagick array patterns. See grid.pattern_magick() for more information.

none

Does nothing. See grid::grid.null() for more information.

pch

Plotting character geometry patterns. See grid.pattern_pch() for more information.

placeholder

Placeholder image array patterns. See grid.pattern_placeholder() for more information.

plasma

Plasma array patterns. See grid.pattern_plasma() for more information.

polygon_tiling

Polygon tiling patterns. See grid.pattern_polygon_tiling() for more information.

regular_polygon

Regular polygon patterns. See grid.pattern_regular_polygon() for more information.

stripe

Stripe geometry patterns. See grid.pattern_stripe() for more information.

text

Text array/geometry patterns. See grid.pattern_text() for more information.

wave

Wave geometry patterns. See grid.pattern_wave() for more information.

weave

Weave geometry patterns. See grid.pattern_weave() for more information.

Custom geometry-based patterns

See https://coolbutuseless.github.io/package/ggpattern/articles/developing-patterns-2.html for more information.

Custom array-based patterns

See https://coolbutuseless.github.io/package/ggpattern/articles/developing-patterns-3.html for more information.

Value

A grid grob object (invisibly in the case of grid.pattern()). If draw is TRUE then grid.pattern() also draws to the graphic device as a side effect.

See Also

https://coolbutuseless.github.io/package/ggpattern/index.html for more details on the ggpattern patterns and their parameters.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 print(names_pattern)
 if (require("grid")) {
   x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
   y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))

   # geometry-based patterns
   # 'stripe' pattern
   grid.newpage()
   grid.pattern("stripe", x_hex, y_hex,
                colour="black", fill=c("yellow", "blue"), density = 0.5)

   # Can alternatively use "gpar()" to specify colour and line attributes
   grid.newpage()
   grid.pattern("stripe", x_hex, y_hex, gp = gpar(col="blue", fill="red", lwd=2))

   # 'weave' pattern
   grid.newpage()
   grid.pattern("weave", x_hex, y_hex, type = "satin",
                colour = "black", fill = "lightblue", fill2 =  "yellow",
                density = 0.3)

   # 'regular_polygon' pattern
   grid.newpage()
   grid.pattern_regular_polygon(x_hex, y_hex, colour = "black",
                                fill = c("blue", "yellow", "red"),
                                shape = c("convex4", "star8", "circle"),
                                density = c(0.45, 0.42, 0.4),
                                spacing = 0.08, angle = 0)

   # can be used to achieve a variety of 'tiling' effects
   grid.newpage()
   grid.pattern_regular_polygon(x_hex, y_hex, color = "transparent",
                                fill = c("white", "grey", "black"),
                                density = 1.0, spacing = 0.1,
                                shape = "convex6", type = "hex")

   # array-based patterns
   # 'image' pattern
   logo_filename <- system.file("img", "Rlogo.png" , package="png")
   grid.newpage()
   grid.pattern("image", x_hex, y_hex, filename=logo_filename, type="fit")

   # 'plasma' pattern
   grid.newpage()
   grid.pattern("plasma", x_hex, y_hex, fill="green")
 }

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