library(sp)
library(raster)
library(rgdal)
library(igraph)
library(RColorBrewer)
# Make list of maps from package database to load, and what functions to use to load them
filelist <-
data.frame(files =
dir(file.path(
find.package("SpaDES", quiet=FALSE), "maps"),
full.names=TRUE, pattern= "tif"),
functions="rasterToMemory",
packages="SpaDES",
stringsAsFactors=FALSE)
# Load files to memory (using rasterToMemory)
mySim <- loadFiles(filelist=filelist)
# put layers into a single stack for convenience
landscape <- stack(mySim$DEM, mySim$forestCover, mySim$forestAge,
mySim$habitatQuality, mySim$percentPine)
# can change color palette
setColors(landscape, n = 50) <- list(DEM=topo.colors(50),
forestCover = brewer.pal(9, "Set1"),
forestAge = brewer.pal("Blues", n=8),
habitatQuality = brewer.pal(9, "Spectral"),
percentPine = brewer.pal("GnBu", n=8))
# Make a new raster derived from a previous one; must give it a unique name
habitatQuality2 <- landscape$habitatQuality ^ 0.3
names(habitatQuality2) <- "habitatQuality2"
# make a SpatialPoints object
caribou <- SpatialPoints(coords=cbind(x=stats::runif(1e2, -50, 50), y=stats::runif(1e2, -50, 50)))
#Plot all maps on a new plot windows - Do not use RStudio window
\notrun{
if (is.null(grDevices::dev.list())) {
dev(2)
} else {
if (any(names(grDevices::dev.list())=="RStudioGD")) {
dev(which(names(grDevices::dev.list())=="RStudioGD")+3)
} else {
dev(max(grDevices::dev.list()))
}
}
}
Plot(landscape, new=TRUE)
# Can overplot, using addTo
Plot(caribou, addTo="landscape$forestAge", size=4, axes=FALSE)
# can add a plot to the plotting window
Plot(caribou, new=FALSE)
# Can add two maps with same name, if one is in a stack; they are given
# unique names based on object name
Plot(landscape, caribou, mySim$DEM)
# can mix stacks, rasters, SpatialPoint*
Plot(landscape, habitatQuality2, caribou)
# can mix stacks, rasters, SpatialPoint*, and SpatialPolygons*
Plot(landscape, caribou)
Plot(habitatQuality2, new=FALSE)
Sr1 = Polygon(cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2))*20-50)
Sr2 = Polygon(cbind(c(5, 4, 2, 5), c(2, 3, 2, 2))*20-50)
Srs1 = Polygons(list(Sr1), "s1")
Srs2 = Polygons(list(Sr2), "s2")
SpP = SpatialPolygons(list(Srs1, Srs2), 1:2)
Plot(SpP)
Plot(SpP, addTo="landscape$forestCover", gp=gpar(lwd=2))
Run the code above in your browser using DataLab