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

Drawing centroid with a solid line instead of a dashed line #43

Closed V-Sher closed 4 years ago

V-Sher commented 4 years ago

I am following the worked example in the documentation (https://rdrr.io/cran/dtwclust/man/tsclusters-methods.html) to plot the time series along with the centroid. By default, the centroid is drawn with a dashed grey line infront of the time series. My goal is to change the linetype to solid (and maybe change color too). But the problem is when I change the parameter linetype = "solid", the centroid is being sent to the background. That is, the other time series are obscuring the centroid. But I know for a fact the solid line is plotted because if I increase the size parameter to 3.5, I can see the centroid time series in the background (see the screenshot below).

Screen Shot 2019-08-23 at 9 48 07 AM

The worked example in the documentation above shows how to change the linetype to solid (line 24 under Examples section) but therein the parameter type = "c" so there is no concept of foreground or background, whereas in my case I want both series and centroid to be plotted but with centroid in front of the time series. Something like this Screen Shot 2019-08-27 at 9 51 22 AM

Any ideas on how that can be done?

asardaes commented 4 years ago

Using the pc_obj from the examples in that documentation entry, the following seems to work:

gg <- plot(pc_obj, type = "sc", linetype = "solid", color = "red", size = 2, plot = FALSE)
gg$layers <- rev(gg$layers)
show(gg)

Rplot

V-Sher commented 4 years ago

Works like a charm. Thank you so much. 👍