R/mapTrajectories.R

Defines functions mapTrajectories

Documented in mapTrajectories

#' 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 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
#' @importFrom graphics plot
#' @importFrom raster rasterFromXYZ
#'
#' @export
#'
#' @examples
#' data is results from the catTrajectory function
#' mapTrajectories(rasList = data,pixelRes = c(1000, 1000),
#' mapTitle = "MAP of CHANGE",titleFont = 1.3, legendFont = 1)

mapTrajectories <- function(rasList,pixelRes = c(1000, 1000),
                            mapTitle = "MAP OF CHANGE",
                            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 <- plot(rasterTrajectories2,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


  )




}
bilintoh/timeComponents documentation built on Dec. 19, 2021, 9:42 a.m.