ptlocator | R Documentation |
the ptlocator
function allows for the selection of data points in
an open graphical device via the locator
function. Closest data points
to the selected positions are determined via Euclidean distance following a scaling of x and y
axes in order to give them equal weighting and remove the influence of differing units or ranges.
Colored points are filled in for the data point that has the lowest distance to the
clicked location, and the result gives the vector positions of the closest x, y data points.
ptlocator(n = NULL, x, y, col = rgb(1, 0, 0, 0.5), pch = 20, ...)
n |
Number of points to select |
x |
Vector of x-axis values for the plotted data |
y |
Vector of y-axis values for the plotted data |
col |
Colors to use for plotting closest data points |
pch |
pch values to use for plotting closest data points |
... |
additional parameters for plotting closest data points |
A vector of point indices
if(interactive()){ set.seed(1) n <- 200 x <- sort(runif(n, min = 0, max = 10*pi)) y <- sin(x) + rnorm(n, sd = 0.2) # Select 10 points at maxima and minima plot(x, y) (pos <- ptlocator(10, x, y)) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.