Learn R Programming

dtwSat (version 0.2.8)

plotArea: Plotting accumulated area

Description

Method for plotting time series of accumulated area.

Usage

plotArea(
  x,
  time.levels = NULL,
  time.labels = NULL,
  class.levels = NULL,
  class.labels = NULL,
  class.colors = NULL,
  perc = TRUE
)

Value

A ggplot object.

Arguments

x

An object of class twdtwRaster.

time.levels

A character or numeric vector with the layers to plot. For plot type ''change'' the minimum length is two.

time.labels

A character or numeric vector with the labels of the layers. It must have the same length as time.levels. Default is NULL.

class.levels

A character or numeric vector with the levels of the raster values. Default is NULL.

class.labels

A character or numeric vector with the labels of the raster values. It must have the same length as class.levels. Default is NULL.

class.colors

a set of aesthetic values. It must have the same length as class.levels. Default is NULL. See scale_fill_manual for details.

perc

if TRUE shows the results in percent of area. Otherwise shows the area in the map units or km2 for no project raster. Default is TRUE.

Author

Victor Maus, vwmaus1@gmail.com

References

Maus:2019dtwSat

Maus:2016dtwSat

See Also

twdtwRaster-class, twdtwApply, plotMaps, plotChanges, and plotDistance.

Examples

Run this code
if (FALSE) {

# Create raster time series
evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat"))
ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat"))
red = brick(system.file("lucc_MT/data/red.tif", package="dtwSat"))
blue = brick(system.file("lucc_MT/data/blue.tif", package="dtwSat"))
nir = brick(system.file("lucc_MT/data/nir.tif", package="dtwSat"))
mir = brick(system.file("lucc_MT/data/mir.tif", package="dtwSat"))
doy = brick(system.file("lucc_MT/data/doy.tif", package="dtwSat"))
timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date")
rts = twdtwRaster(evi, ndvi, red, blue, nir, mir, timeline = timeline, doy = doy)

# Read field samples 
field_samples = read.csv(system.file("lucc_MT/data/samples.csv", package="dtwSat"))
proj_str = scan(system.file("lucc_MT/data/samples_projection", 
                package="dtwSat"), what = "character")

# Split samples for training (10%) and validation (90%) using stratified sampling 
library(caret) 
set.seed(1)
I = unlist(createDataPartition(field_samples$label, p = 0.1))
training_samples = field_samples[I,]
validation_samples = field_samples[-I,]

# Create temporal patterns 
training_ts = getTimeSeries(rts, y = training_samples, proj4string = proj_str)
temporal_patterns = createPatterns(training_ts, freq = 8, formula = y ~ s(x))

# Run TWDTW analysis for raster time series 
log_fun = weight.fun=logisticWeight(-0.1,50)
r_twdtw = twdtwApply(x=rts, y=temporal_patterns, weight.fun=log_fun, format="GTiff", 
                     overwrite=TRUE)
                     
# Classify raster based on the TWDTW analysis 
r_lucc = twdtwClassify(r_twdtw, format="GTiff", overwrite=TRUE)

plotArea(r_lucc)

plotArea(r_lucc, perc=FALSE)

}

Run the code above in your browser using DataLab