## Not run:
# 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 <- cbind(x = stats::runif (1e2, -50, 50), y = stats::runif (1e2, -50, 50)) %>%
# SpatialPoints(coords = .)
#
# # use factor raster to give legends as character strings
# ras <- raster(matrix(sample(1:4, size=12, replace=TRUE),
# ncol=4, nrow=3))
# # needs to have a data.frame with ID as first column - see ?raster::ratify
# levels(ras) <- data.frame(ID=1:4, Name=paste0("Level",1:4))
# if (interactive()) Plot(ras, new=TRUE)
#
# # Arbitrary values for factors
# levels <- c(1,2,7)
# ras <- raster(matrix(sample(levels, size=12, replace=TRUE),
# ncol=4, nrow=3))
# levels(ras) <- data.frame(ID=levels, Name=sample(LETTERS,3))
#
# # SpatialPolygons
# 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)
#
# if (interactive()) {
# Plot(ras, new = TRUE)
#
# # dev(2)
#
# 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)
# Plot(SpP)
# Plot(SpP, addTo = "landscape$forestCover", gp = gpar(lwd = 2))
# }
#
# ## End(Not run)
Run the code above in your browser using DataLab