Skip to content

Commit 12dbee9

Browse files
committedSep 22, 2022
added path_colours to frames_graph
1 parent a4c70c4 commit 12dbee9

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed
 

‎NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ importFrom(ggplot2,theme)
7070
importFrom(ggplot2,theme_bw)
7171
importFrom(ggplot2,waiver)
7272
importFrom(gifski,gifski)
73+
importFrom(grDevices,rainbow)
7374
importFrom(lubridate,"day<-")
7475
importFrom(lubridate,"hour<-")
7576
importFrom(lubridate,"minute<-")

‎R/frames_graph.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#' @details To later on side-by-side join spatial frames created using \code{\link{frames_spatial}} with frames created with \code{\link{frames_graph}} for animation,
1717
#' equal inputs must have been used for both function calls for each of the arguments \code{m}, \code{r_list}, \code{r_times} and \code{fade_raster}.
1818
#'
19+
#' If argument \code{path_colours} is not defined (set to \code{NA}), path colours can be defined by adding a character column named \code{colour} to \code{m}, containing a colour code or name per row (e.g. \code{"red"}. This way, for example, column \code{colour} for all rows belonging to individual A can be set to \code{"green"}, while column \code{colour} for all rows belonging to individual B can be set to \code{"red"}.
20+
#' Colours could also be arranged to change through time or by behavioral segments, geographic locations, age, environmental or health parameters etc. If a column name \code{colour} in \code{m} is missing, colours will be selected automatically. Call \code{colours()} to see all available colours in R.
21+
#'
1922
#' @return An object of class \code{moveVis}. If \code{return_data} is \code{TRUE}, a \code{data.frame} is returned (see \code{return_data}).
2023
#'
2124
#' @author Jakob Schwalb-Willmann
@@ -72,7 +75,7 @@
7275
#' @seealso \code{\link{frames_spatial}} \code{\link{join_frames}} \code{\link{animate_frames}}
7376
#' @export
7477

75-
frames_graph <- function(m, r_list, r_times, r_type = "gradient", fade_raster = FALSE, crop_raster = TRUE, return_data = FALSE, graph_type = "flow", path_size = 1, path_legend = TRUE, path_legend_title = "Names",
78+
frames_graph <- function(m, r_list, r_times, r_type = "gradient", fade_raster = FALSE, crop_raster = TRUE, return_data = FALSE, graph_type = "flow", path_size = 1, path_colours = NA, path_legend = TRUE, path_legend_title = "Names",
7679
val_min = NULL, val_max = NULL, val_by = 0.1, verbose = T){
7780

7881
## check input arguments
@@ -93,6 +96,7 @@ frames_graph <- function(m, r_list, r_times, r_type = "gradient", fade_raster =
9396
if(!is.logical(fade_raster)) out("Argument 'fade_raster' has to be either TRUE or FALSE.", type = 3)
9497

9598
if(!is.numeric(path_size)) out("Argument 'path_size' must be of type 'numeric'.", type = 3)
99+
if(is.character(path_colours)) if(length(path_colours) != n.indiv(m)) out("Argument 'path_colours' must be of same length as the number of individual tracks of 'm', if defined. Alternatively, use a column 'colour' for individual colouring per coordinate within 'm' (see details of ?frames_spatial).", type = 3)
96100
if(!is.logical(path_legend)) out("Argument 'path_legend' must be of type 'logical'.", type = 3)
97101
if(!is.character(path_legend_title)) out("Argument 'path_legend_title' must be of type 'character'.", type = 3)
98102
if(!is.logical(return_data)) out("Argument 'return_data' must be of type 'logical'.", type = 3)
@@ -115,7 +119,7 @@ frames_graph <- function(m, r_list, r_times, r_type = "gradient", fade_raster =
115119

116120
## create data.frame from m with frame time and colour
117121
out("Processing movement data...")
118-
m.df <- .m2df(m)
122+
m.df <- .m2df(m, path_colours = path_colours)
119123
.stats(max(m.df$frame))
120124

121125
## create raster list

‎R/moveVis-internal.R

+11-6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ repl_vals <- function(data, x, y){
102102
if(isTRUE(verbose)) pbapply(X, MARGIN, FUN, ...) else apply(X, MARGIN, FUN, ...)
103103
}
104104

105+
106+
#' moveVis path standard colours
107+
#' @importFrom grDevices rainbow
108+
#' @noRd
109+
.standard_colours <- function(n){
110+
grDevices::rainbow(n)
111+
}
112+
105113
#' split movement by tail length
106114
#' @importFrom move n.indiv timestamps trackId
107115
#' @noRd
@@ -116,16 +124,13 @@ repl_vals <- function(data, x, y){
116124

117125
## handle colours, either provided as a field in m or argument or computed randomly
118126
m.info <- methods::as(m, "data.frame")
127+
128+
# path colours
119129
if(all(!is.character(path_colours), !all(is.na(m.info$colour)))){
120-
121-
## get colours from column
122130
m.df$colour <- as.character(m.info$colour)
123131
} else{
124132
if(!is.character(path_colours)){
125-
126-
path_colours <- c("red", "green", "blue", "yellow", "darkgreen", "orange", "deepskyblue", "darkorange", "deeppink", "navy")
127-
path_colours <- c(path_colours, sample(grDevices::colours()[-sapply(path_colours, match, table = grDevices::colours())]))
128-
#path_colours <- sample(rep(path_colours, ceiling(n.indiv(m) / length(path_colours))))
133+
path_colours <- .standard_colours(n.indiv(m))
129134
}
130135
m.df$colour <- repl_vals(m.df$id, unique(m.df$id), path_colours[1:n.indiv(m)])
131136
}

‎man/frames_graph.Rd

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.