add_colourscale: Add scale to frames

View source: R/add_colourscale.R

add_colourscaleR Documentation

Add scale to frames

Description

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

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 defintion 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. Optioanlly, 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.

Author(s)

Jakob Schwalb-Willmann

See Also

frames_spatial frames_graph animate_frames

Examples

library(moveVis)
library(move)

data("move_data", "basemap_data")
# align movement
m <- align_move(move_data, res = 4, unit = "mins")

# create spatial frames with frames_spatial:
r_list <- basemap_data[[1]]
r_times <- basemap_data[[2]]

## Not run: 
frames <- frames_spatial(m, r_list = r_list, r_times = r_times, r_type = "gradient",
                         fade_raster = TRUE)
frames[[100]] # take a look at one of the frames

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


# let's make up some classification data with 10 classes
r_list <- lapply(r_list, function(x){
  y <- raster::setValues(x, round(raster::getValues(x)*10))
  return(y)
})
# turn fade_raster to FALSE, since it makes no sense to temporally interpolate discrete classes
frames <- frames_spatial(m, r_list = r_list, r_times = r_times, 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]]

## End(Not run)


16EAGLE/moveVis documentation built on March 4, 2024, 1:35 a.m.