Skip to contents

This function adjusts the colour scales of frames created with frames_spatial and custom map imagery using ggplot2.

Usage

add_colourscale(
  frames,
  type,
  colours,
  labels = waiver(),
  na.colour = "grey50",
  na.show = TRUE,
  legend_title = NULL,
  verbose = TRUE
)

Arguments

frames

an object of class moveVis created with frames_spatial.

type

character, either "gradient" or "discrete". Must be equal to the definition of argument r_type with which frames have been created (see frames_spatial).

colours

character, a vector of colours. If type = "discrete", number of colours must be equal to the number of classes contained in the raster imagery with which frames have been created. Optionally, the vector can be named to associate map values with colours and define the scale limits, e.g. c("-1" = "red", "0" = "blue", "1" = "green")

labels

character, a vector of labels with the same length as colours. Ignored, if type = "gradient".

na.colour

character, colour to use for missing values.

na.show

logical, whether to display NA values in discrete scaling. Ignored, if type = "gradient".

legend_title

character, a legend title.

verbose

logical, if TRUE, messages and progress information are displayed on the console (default).

Value

A frames object of class moveVis.

Details

Instead of using this function, you can use add_gg to apply any ggplot2 on moveVis frames yourself.

Author

Jakob Schwalb-Willmann

Examples

library(moveVis)
library(move2)
library(terra)
#> terra 1.8.60

data("move_data", package = "moveVis")
r <- readRDS(example_data(file = "raster_NDVI.rds"))

# align movement
m <- align_move(move_data, res = units::set_units(4, "min"))
#> Temporal resolution of 4 [min] is used to align trajectories.

if (FALSE) { # \dontrun{
# create spatial frames with frames_spatial:
frames <- frames_spatial(
  m, r, r_type = "gradient", fade_raster = TRUE
)
frames[[100]] # take a look at one of the frames

# change the colour scale of all frames
frames <- add_colourscale(
  frames, type = "gradient", colours = c("orange", "white", "darkgreen"),
  legend_title = "NDVI"
)
frames[[100]]

r <- terra::sds(lapply(r, function(x){
  y <- x
terra::values(y) <- round(terra::values(y)*10)
  return(y)
}))

# turn fade_raster to FALSE, since it makes no sense to temporally interpolate discrete classes
frames <- frames_spatial(
  m, r, r_type = "discrete",
  fade_raster = FALSE
)
frames[[100]]
# now, let's assign a colour per class value to frames
colFUN <- colorRampPalette(c("orange", "lightgreen", "darkgreen"))
cols <- colFUN(10)
frames <- add_colourscale(
  frames, type = "discrete", colours = cols, legend_title = "Classes"
)
frames[[100]]
} # }