to_closest | R Documentation |
to_closest helps in changing the longitude and latitude values of occurrences with no environmental data, so they move to the closest pixel of a raster layer that contains relevant information. This process prevents NAs in future analyses.
to_closest(data, longitude, latitude, raster_layer, limit_distance)
data |
data.frame or matrix of occurrence records. Columns must include longitude and latitude. Other columns are optional and wont be changed. |
longitude |
(character) name of the column with longitude data. |
latitude |
(character) name of the column with latitude data. |
raster_layer |
RasterLayer to be used as a reference. |
limit_distance |
(numeric) maximun distance in km at which an occurrence could be to be moved. Records farther than this distance wont be moved. |
A data.frame with the corrected coordinates and four additional columns.
The first of the new columns indicates the condition of the coordinates:
Correct, if it was not moved because it was on a pixel with data; Moved, if
it was moved to the nearest pixel; and Not_moved, if it was not moved because
the occurrence was farther than the limit_distance
to the closest pixel.
The second new column indicates the distance to the closest pixel with data.
The other two additional columns will contain the initial longitudes and
latitudes.
data <- read.csv(system.file("extdata", "occurrences.csv",
package = "ellipsenm"))
var <- raster::raster(list.files(system.file("extdata", package = "ellipsenm"),
pattern = "bio", full.names = TRUE)[1])
raster::plot(var)
out <- data.frame(as.character(data$species[1]), rbind(c(-103, 23), c(-99, 22.5),
c(-103.5, 25.6), c(-99, 27.3)))
colnames(out) <- colnames(data)
data <- rbind.data.frame(data, out)
points(data[, 2:3])
data1 <- to_closest(data, longitude = "longitude", latitude = "latitude",
raster_layer = var, limit_distance = 70)
points(data1[, 2:3], col = "red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.