View source: R/ts_flow_frames.R
ts_flow_frames | R Documentation |
Create a series of charts of a raster time series
ts_flow_frames(
r_list,
positions = NULL,
position_names = NULL,
band_names = NULL,
band_colors = NULL,
val_min = NULL,
val_max = NULL,
val_by = NULL,
plot_size = 1,
position_legend = NULL,
legend_position = "right",
band_legend = NULL,
band_legend_title = NULL,
position_legend_title = NULL,
pbuffer = NULL,
plot_function = "line",
aes_by_pos = TRUE,
FUN = NULL,
return_df = FALSE,
...
)
r_list |
list of rasters, as generated by |
positions |
(Optional) object containing the coordinates. One of
If no positions are specified, one position is assumed to be the entire extent of the rasters. |
position_names |
(Optional) character, names of the positions to be added in legend or text. By default, will create placeholder names by combining the object type and Id (Example: "Polygon 3") |
band_names |
(Optional) character, names of the bands to be added in legend, if |
band_colors |
(Optional) character, colors which represent the bands in the plot. Must be in matching order to |
val_min |
(Optional) numeric, minimum value of the y-axis. By default chooses a rounded minimum value of the rasters contained within |
val_max |
(Optional) numeric, maximum value of the y-axis. By default chooses a rounded maximum value of the rasters contained within |
val_by |
(Optional) numeric, interval value of the y-axis. Default is |
plot_size |
(Optional) numeric, size for the ggplot objects. Default is |
position_legend |
(Optional) logical. If |
legend_position |
(Optional) character, position of the legend. Use |
band_legend |
(Optional) logical. If |
band_legend_title |
(Optional) character, title of the band legend. Default is |
position_legend_title |
(Optional) character, title of the band legend. Default is |
pbuffer |
(Optional) numeric. The radius of a buffer around each object which will be applied before extraction. By default, no buffer is used. |
plot_function |
(Optional) character or function, type of the plots to produce. Currently supported are
Alternatively, a custom function with similar structure and arguments can be passed to create other types of plots. Default is |
aes_by_pos |
(Optional) logical. If |
FUN |
(Optional) function to summarize the values (e.g. mean) during the extraction. See extract for more details. Default is |
return_df |
(Optional) logical. Return a dataframe with the extracted values instead of a plot? This can be useful for experimenting with plot creation. Default is |
... |
(Optional) additional arguments for |
Values are extracted using extract and plotted on a ggplot.
The type of the ggplot is specified by plot_function
. Currently supported are "line"
and "violin"
as well as custom functions which accept similar inputs.
The function may fail for large polygons and long time series. Be aware that if ts_raster
is used with fade
, interpolation may be used to generate raster values.
A list of ggplots, one for each element of r_list
.
Johannes Mast
ts_raster
#' #Setup
library(rtsVis)
# Load example dataset at a greatly increased interval
x_list <- MODIS_SI_ds[seq(1,length(MODIS_SI_ds),30)]
x_dates <- do.call(c, lapply(MODIS_SI_ds,attr,"time") )[seq(1,length(MODIS_SI_ds),30)]
#Fill NAs
x_list_filled <- ts_fill_na(x_list)
#Make a sequence of output dates, double the length of input dates
out_dates <-seq.POSIXt(from = x_dates[1],
to = x_dates[length(x_dates)],length.out = length(x_dates)*2 )
#For each output date, interpolate a raster image from the input files
r_list_out <- ts_raster(r_list = x_list_filled,
r_times = x_dates,
out_times = out_dates,
fade_raster = TRUE)
#Create the frames
# as from the desired layers
r_frames <- ts_makeframes(x_list = r_list_out,samplesize = 10,
l_indices = c(1,4,3))
# Create a line plot from the data extracted over points
points <- SI_positions$points #Polygons of Slovenian municipalities covered by the raster
flow_frames_point_line <- rtsVis::ts_flow_frames(r_list = r_list_out,
position_names = c("Ljubljana","Ivancna Gorica","Dolenjske Toplice","Loski Potok"),
band_names = c("620 - 670","841 - 876","459 - 479","545 - 565"),
positions = points,
band_colors = c("firebrick3","darkorchid3","dodgerblue3","olivedrab3"),
band_legend_title = "Wavelength [nm]",
position_legend_title = "Obcina",
legend_position = "bottom",
position_legend = FALSE,
band_legend=TRUE,aes_by_pos = TRUE)
#Check one of the frames
flow_frames_point_line[[5]]
# Create a violin plot from the data extracted over polygons
# polygons <- SI_positions$polygons
#flow_frames_poly_vio <-
#rtsVis::ts_flow_frames(r_list = r_list_out,
# position_names = c("Radece","Ljubljana","Kocevje"),
# band_names = c("620 - 670","841 - 876","459 - 479","545 - 565"),
# positions = polygons,
# band_colors = c("firebrick3","darkorchid3","dodgerblue3","olivedrab3"),
# band_legend_title = "Wavelength [nm]",
# position_legend_title = "Obcina",
# position_legend = FALSE,
# legend_position = "left",
# band_legend=TRUE,aes_by_pos = FALSE,
# plot_function = "vio")
#Check one of the frames
# flow_frames_poly_vio[[5]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.