animate_raster
animates raster data provided as list of raster
class objects. The function creates an animated GIF file and saves it into the output directory.
animate_raster(layer, out_dir, conv_dir = "convert",
layer_type = "gradient", layer_stretch = "none",
layer_col = c("sandybrown", "white", "darkgreen"), layer_nacol = "white",
static_data = NA, static_gg = NA, img_title = "title",
img_sub = "subtitle", img_caption = "caption", img_labs = "labs",
legend_title = "", legend_limits = NA, legend_labels = "auto",
map_elements = TRUE, scalebar_col = "white", north_col = "white",
frames_nmax = 0, frames_interval = 0.04, frames_nres = 1,
frames_width = NA, frames_height = NA, out_name = "final_gif",
log_level = 1, log_logical = FALSE, ...)
list. List of raster objects.
character. Output directory for the GIF file creation.
character. Command or directory to call the ImageMagick convert tool (default to be convert
). You can use conv_dir = get_imconvert()
to search for the right command/tool directory and/or get the required software.
charachter. Layer type. Can be either "RGB
" (if layer is a rasterBrick class object), "gradient
" or "discrete
". Default is "gradient
".
character. Ignored, if layer_type
is not "RGB". Either "none", "lin", "hist", "sqrt" or "log" for no stretch, linear, histogram, square-root or logarithmic stretch. Default is "none".
character vector. Two or more colours to be used for displaying the background layer. If layer_type = "gradient"
, a colour ramp between the colous is calcualted. If layer_type = "discrete"
, the colours will be used per value range. Ignored, if layer_type = "RGB"
.
character. Colour to be displayed for NA values. Default is "white".
data.frame. Data (e.g. static points) to be displayed within the spatial plot of the GIF output. At least, "x", "y" columns for the coordinates and "names" for the naming of the point have to be included. If "static_gg" remains unspecified, "static_data" is plottet as points to the output map, annotated with their namings. Points outside the frame extent are not displayed. See "static_gg" for further options.
character. One or several ggplot2
functions, concatenated by "+" specifying how "static_data" should be displayed, e.g. using geom_point
and geom_text
for displaying points annotated with text. ggplot2 data
and aes, aes_
arguments etc. need to referr to the columns specified in "static_data". As default, "static_data" is plotted as geom_point
and geom_label
.
character. Titel to be displayed above the animated plot. If not specified, no title will be displayed.
character. Subtitel to be displayed underneath the title. If not specified, no subtitle will be displayed.
character. Caption to be displayed underneath the plot. If not specified, no caption will be displayed.
character. Axis titles to be displayed at the x and y axis of the plot. If not specified, labs will be computed depending on the projection or will be "x" and "y".
character. Title to be displayed above the basemap layer legend (if layer_type is not "RGB"
). Ignored, if layer = "basemap"
.
numeric vector. Fixed minimum and maximum limit values of the legend (gradient layer type). Default is NA for data-depending minimum and maximum values. Ignored, if layer_type
is "discrete" or "RGB".
character vectors. Label for each legend break class. If set to "auto", values are displayed. Default is "auto".
logical. If FALSE
, map elements (north arrow and scale bar) are hidden. Default is TRUE
.
character. Colour of the scalebar text. Default is "white".
character. Colour of the north arrow. Default is "white".
numeric. Number of maximum frames. If set, the animation will be stopped, after the specified number of frames is reached. Default is 0 (displaying all frames).
numeric. Duration, each frame is displayed (in seconds). Default is .04.
numeric. Interval of which frames of all frames should be used (nth elements). Default is 1 (every frame is used). If set to 2, only every second frame is used.
numeric. Number of pixels of frame width. Default is 600 (with stats plots 1000).
numeric. Number of pixels of frame height. Defualt is 600.
character. Name of the output file. Default is "final_gif".
numeric. Level of console output given by the function. There are three log levels. If set to 3, no messages will be displayed except erros that caused an abortion of the process. If set to 2, warnings and errors will be displayed. If set to 1, a log showing the process activity, wanrnings ans errors will be displayed.
logical. For large processing schemes. If TRUE
, the function returns TRUE
when finished processing succesfully.
optional arguments.
None or logical (see log_logical
). The output GIF file is written to the ouput directory.
animate_raster
is partly based on the animation
package and needs the convert
tool of the ImageMagick
software package to assemble the GIF file. The command or directory to the convert tool needs to be provided with conv_dir
. Please use get_imconvert
to search for the convert command/tool directory on your system or to automatically download and install the required software. See get_imconvert
for details.
# NOT RUN {
#Create a list of several raster objects to be displayed one after another
#If layer_type = RGB, use a brick class obejct with RGB bands!
layer <- list(raster1, raster2, raster2)
#Get your convert directory/command
conv_dir <- get_imconvert()
#Specify the output directory, e.g.
out_dir <- "/out/test"
#or to a temporary directory:
out_dir <- paste0(tempdir(),"/test")
dir.create(out_dir)
#Call animate_raster
animate_raster(layer,out_dir = our_dir, conv_dir = conv_dir, layer_type = "RGB")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab