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)

clickCoordinates(n = 1)

.clickCoord(X, n = 1, gl = NULL)

Arguments

n

The number of mouse clicks to do.

devNum

The device number for the new plot to be plotted on.

plot.it

Logical. If TRUE a new plotting window is made for the new extent. Default TRUE.

X

The raster object whose values will be returned where mouse clicks occur.

gl

An object created by a call to grid.locator.

Value

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.

Details

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.

Examples

# NOT RUN {
  library(igraph)
  library(raster)

  files <- system.file("maps", package = "quickPlot") %>%
    dir(., full.names = TRUE, pattern = "tif")
  maps <- lapply(files, function(x) raster(x))
  names(maps) <- sapply(basename(files), function(x) {
    strsplit(x, split = "\\.")[[1]][1]
  })
  landscape <- stack(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)
# }