nr_polyline: Draw a polyline on a native raster image

View source: R/nr-draw.R

nr_polylineR Documentation

Draw a polyline on a native raster image

Description

Draw a polyline on a native raster image

Usage

nr_polyline(
  nr,
  x,
  y,
  color = "black",
  linewidth = 1,
  mitre_limit = linewidth,
  close = FALSE,
  use_alpha = TRUE
)

Arguments

nr

native raster image

x, y

Vectors of point coordinates

color

Color as a character string. Either a standard R color (e.g. 'blue', 'white') or a hex color of the form #rrggbbaa, #rrggbb, #rgba or #rgb

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.

mitre_limit

Limit the size of the mitre when two lines meet at an acute angle and linewidth is greater than 1. Default: same as line linewidth which mostly looks OK.

close

Should the polyline be closed? I.e. should a line be drawn between the last point and the first point? Default: FALSE

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

Other drawing functions: nr_circle(), nr_polygon(), nr_rect(), nr_tri_mesh()

Examples

w <- 200
h <- 150
nr <- nr_new(w, h, 'grey80')

N  <- 20
theta <- seq(0, 2 * pi, length.out = N)
xs <- w/2 + 50 * cos(theta)
ys <- h/2 + 50 * sin(theta)

nr_polyline(nr, xs, ys)
nr_point(nr, xs, ys, col = 'red')
plot(nr)

nara documentation built on May 28, 2026, 5:07 p.m.