I've got a RasterStack composed of a four rasters. See below:
# Reproducible examples
kiwi <- raster(xmn = -180, xmx = 180, ymn = -56, ymx = 84, res = 1)
kiwi[] <- sample(2:35, ncell(kiwi), replace = T)
banana <- raster(xmn = -180, xmx = 179.9999, ymn = -56.00081, ymx = 83.99917,
res = 1)
banana[] <- sample(2:100, ncell(banana), replace = T)
apple <- raster(xmn = -180, xmx = 180, ymn = -56, ymx = 84, res = 1)
apple[] <- sample(4:100, ncell(apple), replace = T)
mango <- raster(xmn = -180, xmx = 180, ymn = -56, ymx = 84, res = 1)
mango[] <- sample(1:90, ncell(mango), replace = T)
# Raster stack
stacked<-stack(kiwi, banana, apple, mango)
I want to reclassify the RasterStack into four categories (tropical
, mediterranean
, boreal
and savannah
) based on some conditions (see below), and then combine into one raster and plot all four categories on a single map.
# Example conditions
kiwi < 10 & banana > 20 & mango > 0.5 == "tropical"
mango > 15 & apple < 10 == "boreal"
I think I need to create a function
and apply it to overlay
but I don't know how to write this function. Does anyone know how to do this?