click_sample: Sample raster values within map categories

View source: R/click_sample.R

click_sampleR Documentation

Sample raster values within map categories

Description

Function for sampling the RGB values at n points of an image within n categories, using the click() function from the raster package. These values can then be used to define thresholds for reclassifying the raster image.

Usage

click_sample(in.raster, cats = NULL, npoints = 10, print.values = FALSE, type = "p", plot.cols = TRUE, ...)

Arguments

in.raster

The raster to sample. Only works for an image file, and bands MUST be named "red", "green", and "blue" (exactly, in that order) for it to work.

cats

A vector of the names of land-use categories of interest (string).

npoints

The number of times to sample each category. More points means more representative results, but generally the default is enough if you make sure that you sample the full range of colours for each category, provided points are well chosen. Default = 10.

print.values

Logical. Print the RGB values of each point as you go. Default = FALSE.

type

Logical. From click. Do you want to plot the points on the image so you know where you've already clicked (and if you miss!). Default = TRUE.

plot.cols

Logical. Produce the plot of max or min colours once sampling is finished. Requires packages ggplot and gridExtra. Default = TRUE.

...

additional parameters passed to plot_colour_table

Value

Returns a list with three objects:

sample.table

Dataframe. The values for each point clicked and the category they were assigned in.

colour.summary

Dataframe. Summary of max, min and mean values for each colour band in each category

colour.plot

Plot. Visualises the values in colour.summary and check they fit expectations.

Author(s)

Alistair Auffret and Adam Kimberley

References

Auffret, A.G., Kimberley, A., et al., 2017, HistMapR: Rapid digitization of historical maps in R, Methods in Ecology and Evolution, doi: 10.1111/2041-210X.12788., Link. GitHub repository.

Hijmans, R.J. (2016) raster: Geographic Data Analysis and Modeling. R package version 2.5-8, http://CRAN.R-project.org/package=raster.

Examples

	data(HistMapRex)
	click_sample(in.raster=ras.smoothed, cats = c("Arable", "Open", "Forest"), npoints = 3, print.values = FALSE, type = "p", plot.cols = TRUE)
	 

AGAuffret/HistMapR documentation built on July 20, 2023, 2:43 a.m.