#three time series
#climate and ndvi in Fagus sylvatica stands in Spain, Germany, and Sweden
#convert to time series list
#scale and center to neutralize effect of different scales in temperature, rainfall, and ndvi
tsl <- tsl_initialize(
x = fagus_dynamics,
name_column = "name",
time_column = "time"
) |>
tsl_transform(
f = f_scale_global #see help(f_scale_global)
)
if(interactive()){
tsl_plot(
tsl = tsl,
guide_columns = 3
)
}
#visualize dynamic time warping
if(interactive()){
#plot pair with cost matrix (default)
distantia_dtw_plot(
tsl = tsl[c("Spain", "Sweden")] #only two time series!
)
#plot pair with distance matrix
distantia_dtw_plot(
tsl = tsl[c("Spain", "Sweden")],
matrix_type = "distance"
)
#plot pair with different distance
distantia_dtw_plot(
tsl = tsl[c("Spain", "Sweden")],
distance = "manhattan", #sed data(distances)
matrix_type = "distance"
)
#with different colors
distantia_dtw_plot(
tsl = tsl[c("Spain", "Sweden")],
matrix_type = "distance",
matrix_color = grDevices::hcl.colors(
n = 100,
palette = "Inferno"
),
path_color = "white",
path_width = 2,
line_color = grDevices::hcl.colors(
n = 3, #same as variables in tsl
palette = "Inferno"
)
)
}
Run the code above in your browser using DataLab