# NOT RUN {
## Load raster landscape
tiny <- raster::raster(system.file("extdata/tiny.asc", package = "grainscape"))
## Create a resistance surface from a raster using an is-becomes reclassification
tinyCost <- raster::reclassify(tiny, rcl = cbind(c(1, 2, 3, 4), c(1, 5, 10, 12)))
## Produce a patch-based MPG where patches are resistance features=1
tinyPatchMPG <- MPG(cost = tinyCost, patch = tinyCost == 1)
## Extract a representative subset of 5 grains of connectivity
tinyPatchGOC <- GOC(tinyPatchMPG, nThresh = 5)
if (interactive()) {
library(ggplot2)
## MPG and showing simplified links among the perimeters of patches
plot(tinyPatchMPG)
## MPG showing links among the nodes of connected patches
plot(tinyPatchMPG, quick = "network")
## MPG showing the shortest paths between patches actually used to
## to calculate link weight values
plot(tinyPatchMPG, quick = "mpgPlot")
## A grain of connectivity network plot with Voronoi boundaries
plot(grain(tinyPatchGOC, 3), quick = "grainPlot")
## Capture plot output for further processing with ggplot
g <- plot(tinyPatchMPG, print = FALSE, theme = FALSE)
g <- g + theme_minimal() + ggtitle("Minimum planar graph") +
theme(plot.title = element_text(size = 20, hjust = 0.5)) +
theme(legend.position = "none") +
xlab("Easting") + ylab("Northing")
g
## To change aesthetics it is best to build the plot from scratch
## using grainscape::ggGS(). See examples therein.
}
# }
Run the code above in your browser using DataLab