These functions use grid.locator
. The primary two user-level functions are
clickValues
and clickExtent
. These functions automatically select
the correct viewport (i.e., map) where the mouse clicks occurred so the user
does not have to manually specify which map is being clicked on.
This works for Raster*
, SpatialPoints*
, and SpatialPolygons*
objects.
clickValues(n = 1)
clickExtent(
devNum = NULL,
plot.it = TRUE,
verbose = getOption("quickPlot.verbose")
)
clickCoordinates(n = 1)
.clickCoord(X, n = 1, gl = NULL)
The number of mouse clicks to do.
The device number for the new plot to be plotted on.
Logical. If TRUE
a new plotting window is made for the
new extent. Default TRUE
.
Numeric or logical. If TRUE
or >0
, then messages will be
shown. If FALSE
or 0
, most messages will be suppressed.
The raster object whose values will be returned where mouse clicks occur.
An object created by a call to grid.locator
.
clickValues
returns the layer names and values at the clicked points.
clickExtent
invisibly returns the extent object, and optionally plots
it in a new device window.
clickCoordinates
returns the xy coordinates in the units of the plot clicked on.
clickValues
is equivalent to running X[SpatialPoints(locator(n))]
, where
X is the raster being clicked on, in base graphics. This function determines which place in the
grid.layout was clicked and makes all appropriate calculations to determine the value
on the raster(s) at that or those location(s). It should be noted that when zooming in
to rasters, plotting of rasters will only allow for complete pixels to be plotted, even
if the extent is not perfectly in line with pixel edges. As a result, when values
returned by this function may be slightly off (<0.5 pixel width).
clickExtent
is for drawing an extent with two mouse clicks on a given Plotted map.
clickCoordinates
is the workhorse function that determines which plot has been
clicked on and passes this plot name and the clicked coordinates to .clickCoord
.
.clickCoord
is intended for internal use and is called by other functions here.
clickExtent
will place the new, zoomed in plot over top of the existing
object. To recover original full object, double click anywhere during an
active clickExtent
. Currently, subsequent clickExtent
is a click on the
original map extent, not the "zoomed in" map extent. See example.
# \donttest{
# clickValues and family are unreliable on Rstudio Server as the plotting device
# does not report its dimensions correctly; this may change in future
# updates to Rstudio
if (interactive() && !isRstudioServer() ) {
files <- system.file("maps", package = "quickPlot")
files <- dir(files, full.names = TRUE, pattern = "tif")
maps <- lapply(files, function(x) terra::rast(x))
names(maps) <- sapply(basename(files), function(x) {
strsplit(x, split = "\\.")[[1]][1]
})
landscape <- c(maps$DEM, maps$forestCover, maps$habitatQuality)
clearPlot()
Plot(landscape)
clickValues(3) # click at three locations on the Plot device
clearPlot()
Plot(landscape)
e <- clickExtent() # click at two locations on the Plot device
print(e)
# repeated zooming to try various places on the original device
for(i in 1:4) clickExtent() # click at two locations on the Plot device
}
# }