add_colourscale.Rd
This function adjusts the colour scales of the animation frames created with frames_spatial
and custom map imagery.
add_colourscale(
frames,
type,
colours,
labels = waiver(),
na.colour = "grey50",
na.show = TRUE,
legend_title = NULL,
verbose = TRUE
)
an object of class moveVis
created with frames_spatial
.
character, either "gradient"
or "discrete"
. Must be equal to the defintion of argument r_type
with which frames
have been created (see frames_spatial
).
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")
character, a vector of labels with the same length as colours
. Ignored, if type = "gradient"
.
character, colour to use for missing values.
logical, whether to display NA values in discrete scaling. Ignored, if type = "gradient"
.
character, a legend title.
logical, if TRUE
, messages and progress information are displayed on the console (default).
A frames object of class moveVis
.
library(moveVis)
library(move)
#> Loading required package: geosphere
#> Loading required package: sp
#> Loading required package: raster
#> Loading required package: rgdal
#> Please note that rgdal will be retired by the end of 2023,
#> plan transition to sf/stars/terra functions using GDAL and PROJ
#> at your earliest convenience.
#>
#> rgdal: version: 1.5-32, (SVN revision 1176)
#> Geospatial Data Abstraction Library extensions to R successfully loaded
#> Loaded GDAL runtime: GDAL 3.4.2, released 2022/03/08
#> Path to GDAL shared files: /Users/runner/work/_temp/Library/rgdal/gdal
#> GDAL binary built with GEOS: FALSE
#> Loaded PROJ runtime: Rel. 8.2.1, January 1st, 2022, [PJ_VERSION: 821]
#> Path to PROJ shared files: /Users/runner/work/_temp/Library/rgdal/proj
#> PROJ CDN enabled: FALSE
#> Linking to sp version:1.5-0
#> To mute warnings of possible GDAL/OSR exportToProj4() degradation,
#> use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
data("move_data", "basemap_data")
# align movement
m <- align_move(move_data, res = 4, unit = "mins")
#> Temporal resolution of 4 [mins] is used to align trajectories.
# create spatial frames with frames_spatial:
r_list <- basemap_data[[1]]
r_times <- basemap_data[[2]]
if (FALSE) {
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]]
}