DescTools (version 0.99.15)

IdentifyA: Identify Points in Plot Lying within a Rectangle or Polygon

Description

Find all the points lying either in a rectangle area, spanned by an upper left point and a bottom-right point clicked by the user or in a polygon area defined by the user.

Usage

IdentifyA(formula, data, subset, poly = FALSE)

Arguments

formula
a formula, such as y ~ x specifying x and y values. Here the formula must be entered that was used to create the scatterplot.
data
a data frame (or list) from which the variables in formula should be taken.
subset
an optional vector specifying a subset of observations to be used.
poly
logical. Defines if a polygon or a rectangle should be used to select the points. Default is rectangle. If a polygon should be used, set this argument to TRUE and select all desired points. The polygon will be closed automatically when finished.

Value

  • Index vector with the points lying within the selected area. The coordinates are returned as text in the attribute "cond".

See Also

identify, locator

Examples

Run this code
# run the example via copy and paste

plot(temperature ~ delivery_min, data=d.pizza)
idx <- IdentifyA(temperature ~ delivery_min, data=d.pizza)

# you selected the following points
d.pizza[idx,]
points(temperature ~ delivery_min, data = d.pizza[idx,], col="green")

# use the attr("cond") for subsets in code
attr(idx, "cond")

# create a group variable for the found points
d.pizza$grp <- seq(nrow(d.pizza)) %in% idx 

# try the polygon option
idx <- IdentifyA(temperature ~ delivery_min, data=d.pizza, poly=TRUE)
points(temperature ~ delivery_min, data = d.pizza[idx,], col="red")

Run the code above in your browser using DataCamp Workspace