draw_grob: Draw a grob.

Description Usage Arguments Examples

View source: R/draw.R

Description

Places an arbitrary grob somewhere onto the drawing canvas. By default, coordinates run from 0 to 1, and the point (0, 0) is in the lower left corner of the canvas.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
draw_grob(
  grob,
  x = 0,
  y = 0,
  width = 1,
  height = 1,
  scale = 1,
  clip = "inherit",
  hjust = 0,
  vjust = 0,
  halign = 0.5,
  valign = 0.5
)

Arguments

grob

The grob to place.

x

The x location of the grob. (Left side if hjust = 0.)

y

The y location of the grob. (Bottom side if vjust = 0.)

width

Width of the grob.

height

Height of the grob.

scale

Scales the grob relative to the rectangle defined by x, y, width, height. A setting of scale = 1 indicates no scaling.

clip

Set to "on" to clip the grob or "inherit" to not clip. Note that clipping doesn't always work as expected, due to limitations of the grid graphics system.

hjust, vjust

Horizontal and vertical justification relative to x.

halign, valign

Horizontal and vertical justification of the grob inside the box.

Examples

1
2
3
4
# A grid grob (here a blue circle)
g <- grid::circleGrob(gp = grid::gpar(fill = "blue"))
# place into the middle of the plotting area, at a scale of 50%
ggdraw() + draw_grob(g, scale = 0.5)

Example output

Loading required package: ggplot2

Attaching package: 'cowplot'

The following object is masked from 'package:ggplot2':

    ggsave

cowplot documentation built on Dec. 30, 2020, 5:07 p.m.