ts_makeframes: Create spatial ggplots of a raster time series

View source: R/ts_makeframes.R

ts_makeframesR Documentation

Create spatial ggplots of a raster time series


Create spatial ggplots of a raster time series


  r_type = NULL,
  minq = 0.02,
  maxq = 0.98,
  samplesize = 1000,
  blacken_NA = FALSE,
  l_indices = NULL,
  alpha = NULL,
  hillshade = NULL,



a list of raster objects.


(Optional) character, one of "discrete", "gradient" or "RGB". By default, attempts to discern the r_type from the content of r_list.


(Optional) numeric, lower quantile boundary for the stretch. Default is 0.02.


(Optional) numeric, upper quantile boundary for the stretch. Default is 0.98.


(Optional) numeric, number of samples per layer to determine the quantile from. See sampleRegular for details on the sampling. Default is 1000.


(Optional) logical. If TRUE: set NA to 0. Default is FALSE.


(Optional) numeric, a vector of layer indices specifying which layers are to be plotted. Should contain 3 values for an RGB image or a single value for a discrete or gradient image. By default, chooses the first three layers if r_type is "RGB" and the first layer if r_type is "discrete" or "gradient".


(Optional) numeric. The opacity of the plot. Default is 1.


(Optional) A raster layer. If one is provided, it will be used as the base layer and plotted with ggR while the raster layers from x_list will be plotted over it with a default alpha of 0.5. By default, no hillshade is used.


(Optional) further arguments for the plotting.


A linear percent stretch will be applied to each band to improve contrast. #

(X - Low_{in}) * \frac{((High_{out}-Low_{out})}{(High_{in}-Low_{in}))} + Low_{out}

# The stretch parameters # High_{out},Low_{out},High_{in},Low_{in} # are calculated separately for each band based on the minq and maxq which are first applied to samplesize regular samples (see sampleRegular) of each individual layer. From these, across all layers belonging to a certain band, the minimum and maximum values are taken as the stretching parameters for the linear stretch, which is performed using rescaleImage. Discrete r_types will not be stretched. To further enhance the plots, consider using functionalities implemented in moveVis, (see http://movevis.org/ ). For example, a northarrow may be added to all frames using add_northarrow.


A list of ggplots


Johannes Mast


# Load example dataset at a greatly increased interval
x_list <- MODIS_SI_ds[seq(1,length(MODIS_SI_ds),25)]
x_dates <- do.call(c, lapply(MODIS_SI_ds,attr,"time") )[seq(1,length(MODIS_SI_ds),25)]

#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))

JohMast/rtsVis documentation built on Aug. 6, 2022, 1:17 a.m.