#' Creates a map showing the spatial distribution of the trajectories.
#'
#' @param rasList A data frame containing the X,Y, and trajectories.
#' @param pixelRes A vector containg the pixel size of the original raster files. The defualt is 1000X1000 meters.
#' @param mapTitle A string of characters describing the map title. The default is "MAP of CHANGE"
#' @param labx A string of characters describing the x-axis. The defaut is "X(m)"
#' @param laby A string of characters describing the y-axis. The defaut is "Y(m)"
#' @param axisFont A numeric value to control the font size for the x and y-axis labels. The defaut is 1.5.
#' @param titleFont A numeric value to control the font size for the map title. The defaut is 1.6.
#' @param legendFont A numeric value to control the font size for the map legend. The default is 1.
#'
#' @return A map of change
#' @import graphics
#' @importFrom raster rasterFromXYZ ratify levels
#' @import dplyr
#'
#' @import utils
#' @import magrittr
#' @import mice
#'
#' @export
#'
mapTrajectories <- function(rasList,pixelRes = c(1000, 1000),
mapTitle = "MAP OF CHANGE",
labx = "X(m)",
laby = "Y(m)",
axisFont = 1.5,
titleFont = 1.3,
legendFont = 1) {
resx <- length(unique(rasList$combinedTrajectory$x))
if(resx > 1 ){
xres <- pixelRes[1]
}else{
resx == 1
xres <- NA
}
resy <- length(unique(rasList$combinedTrajectory$y))
if(resy > 1 ){
yres <- pixelRes[1]
}else{
resy == 1
yres <- NA
}
dfRasterTrajectories <- as.data.frame(rasList[1])
rasterTrajectories2 <- rasterFromXYZ(dfRasterTrajectories, res = c(yres,xres))
myColv2 <- c('White','#c4c3c0','#666666', "#000080", "#8b0000")
trajetoryCalss_v1 <- c("Mask","Absence","Presence","Gain","Loss")
mapCol <- colorMatch(rasterTrajectories2)
trajectorypPlot <- sp::plot(rasterTrajectories2,
xlab = labx,
ylab = laby,
cex.lab = axisFont,
col = as.character(mapCol$myColv1),
legend = FALSE)
title(mapTitle, line = 0.2,cex.main = titleFont)
par(xpd = TRUE)
legend("bottomright", title = "Legend",
legend = trajetoryCalss_v1,
fill = myColv2,
border = TRUE,
bty = "n",
cex = legendFont,
text.font = 2
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.