linesegments: Add line segments connecting pairs of points, to a plot

View source: R/linesegments.R

linesegmentsR Documentation

Add line segments connecting pairs of points, to a plot

Description

Accepts vectors of x and y values of pairs of points (e.g., longitude and latitude), reformats them and adds line segments to an existing plot. Each line segment drawn connects one point its paired point. The two sets of points have to be equal in length, set up as pairs.

Usage

linesegments(xfrom, yfrom, xto, yto, ...)

Arguments

xfrom

required numeric vector of x values for starting points

yfrom

required numeric vector of y values for starting points

xto

required numeric vector of x values for ending points

yto

required numeric vector of y values for ending points

...

optional additional parameters to pass to lines

Details

This function also silently returns a matrix of two columns. Each column is a vector that has elements sequenced in groups of three – the from point, then the to point, then NA to signify a break in line drawing. See lines

Value

Draws lines(), one line segment from each starting point to its corresponding ending point.

See Also

testpoints and get.nearest

Examples

 t10  <- testpoints(10,  minlat = 25, maxlat = 45, minlon = -100, maxlon = -60)
 t100 <- testpoints(100, minlat = 25, maxlat = 45, minlon = -100, maxlon = -60)
 nears=as.data.frame( get.nearest(t10, t100, return.latlons=TRUE) )
 plot(t10)
 plot(t100, pch='.')
 linesegments(nears$fromlon, nears$fromlat, nears$tolon, nears$tolat)

ejanalysis/proxistat documentation built on April 2, 2024, 10:13 a.m.