texture_grob: Draw rectangle filled with a texture image

Description Usage Arguments Examples

View source: R/texture-grob.R

Description

A texture grob is a grid grob that draws a rectangle filled with an image. The image will be tiled if it is not large enough to fill the entire space of the rectangle.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
texture_grob(
  img,
  x = unit(0.5, "npc"),
  y = unit(0.5, "npc"),
  width = unit(1, "npc"),
  height = unit(1, "npc"),
  just = c(0, 0),
  img_width = unit(1, "null"),
  img_height = NA,
  nrow = NA,
  ncol = NA,
  hjust = 0.5,
  vjust = 0,
  fill = "#E8E8E8",
  color = "#000000",
  lty = 1,
  lwd = 1,
  clip = "on",
  repmax = 500,
  interpolate = TRUE
)

Arguments

img

The image, in magick format

x

Unit object specifying x position of rectangle

y

Unit object specifying y position of rectangle

width

Unit object specifying the rectangle width

height

Unit object specifying the rectangle height

just

Vector of two numeric values specifying horizontal and vertical justification of rectangle relative to x and y.

img_width

Unit object specifying the width of the texture image. If "null" unit is used, then the image width is calculated relative to the rectangle width.

img_height

Unit object specifying the height of the texture image. If "null" unit is used, then the image height is calculated relative to the rectangle height.

nrow

Number of image rows. If NA, is calculated automatically from the available space.

ncol

Number of image columns. If NA, is calculated automatically from the available space.

hjust

Horizontal justification of images.

vjust

Vertical justification of images.

fill

Fill color for rectangle.

color

Border color for rectangle.

lty

Line type for border.

lwd

Line width for border.

clip

Should images be clipped to rectangle extent? "on" means yes, "off" means no.

repmax

Maximum number of image repetitions. By default set to 500. This is a safety check against bad parameter settings that might create hundreds of thousands of images or more.

interpolate

A logical value indicating whether to linearly interpolate the image (the alternative is to use nearest-neighbour interpolation, which gives a more blocky result).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
img <- magick::image_read("https://jeroen.github.io/images/Rlogo.png")

grid.newpage()
tg1 <- texture_grob(
  img,
  x = unit(.2, "npc"), y = unit(.05, "npc"),
  width = unit(.1, "npc"), height = unit(.9, "npc"),
  img_width = unit(.5, "in"), ncol = 1
)
tg2 <- texture_grob(
  img,
  x = unit(.5, "npc"), y = unit(.05, "npc"),
  width = unit(.3, "npc"), height = unit(.6, "npc"),
  img_width = unit(.5, "in"), ncol = 1
)

grid.draw(tg1)
grid.draw(tg2)

clauswilke/ggtextures documentation built on Nov. 14, 2020, 5:38 p.m.