Draw rectangles on a native raster image

nr_rect(
  nr,
  x,
  y,
  w,
  h,
  fill = "black",
  color = NA,
  hjust = 0,
  vjust = 0,
  linewidth = 1,
  use_alpha = TRUE
)

Arguments

nr

native raster image

x, y

coordinates of lower left corner of rectangle. [vector]

w, h

width and height of rectangle. [vector]

fill

interior fill color [vector]

color

outline color. Default: NA. [vector]

hjust, vjust

specify horizontal and vertical justification of the handle on the src image to be placed at (x, y) within the dst image. Default (0, 0) is to use the top-left corner of the image as the handle. Use (0.5, 0.5) to centre the src image at the dst location (x, y)

linewidth

Line linewidth. Default: 1. If linewidth = 1 then a naive version of Bresenham is used to draw the points. If linewidth is greater than 1, then the line is convert to a triangle strip and rendered as polygons.

use_alpha

Use alpha channel when drawing? Logical. Default: TRUE

Value

Invisibly return the supplied native raster image which was been modified in-place

See also

Examples

N <- 200
nr <- nr_new(N, N, 'grey80')
nr_rect(nr, x = c(0, N/2 - 1), y = c(0, N/2 - 1), w = N/2, h = N/4, 
        fill = 'blue', color = c('red', 'green'), linewidth = 3)
plot(nr)