asardaes / dtwclust

R Package for Time Series Clustering Along with Optimizations for DTW
https://cran.r-project.org/package=dtwclust
GNU General Public License v3.0
252 stars 29 forks source link

Plotting Clusters #62

Closed lsemployeeoftheyear closed 1 year ago

lsemployeeoftheyear commented 1 year ago

Hey,

I'm trying to plot clusters I made using SBD distance, but my data is pretty big (~12k series) and so the plots are largely unreadable. Is there any way to either

  1. Sample down the number of series plotted using dtwclust's base plot function
  2. Apply a znorm to the plot

Thanks!

asardaes commented 1 year ago

Hello, I imagine you could subset yourself and simply alter the datalist and cluster slots from the result, for example:

tsc <- tsclust(CharTraj, k = 20L, distance = "sbd", trace = TRUE)

cluster <- 1L # which cluster to focus on
upper_limit <- 2L # max number of series from that cluster

subset_ids <- which(tsc@cluster == cluster)[1L:upper_limit]
subset_ids <- subset_ids[!is.na(subset_ids)]

tsc@datalist <- tsc@datalist[subset_ids]
tsc@cluster <- tsc@cluster[subset_ids]

plot(tsc, clus = cluster)