R中的TSClust绘图方法:使用实线代替虚线

时间:2019-08-23 01:56:02

标签: r dtw tsclust

我正在dtwclust包中使用tsclust函数对时间序列进行聚类。现在有了簇,我想将它们连同它们的质心一起绘制。默认实现是黑色虚线表示簇质心。我的目标是将质心绘制成实线而不是虚线,并且将其颜色绘制为红色而不是黑色。

我已阅读此处(https://cran.mtu.edu/web/packages/dtwclust/dtwclust.pdf)和第66页上“绘图”部分下的文档,该文档指出要更改线型和颜色,必须使用省略号(...)。我尝试这样做,

这是我的代码段,为您提供概述:

head(zu)


    W1 W2 W3 W4 W5 W6 W7 W8 W9 W10 W11 W12
1     0    0    1    0    0    0    0    0    0    0   0   0
2     1    0    0    1    1    6    2    0    0    0   0   0
3     0    0    1    0    0    0    2    0    1    1   2   0
4     0    1    0    0    0    0    0    0    0    0   0   0
5     0    0    1    0    0    0    0    0    0    0   0   0

这是创建的聚类对象

clust.hier.disc1.clust1 <- tsclust(zu, type = "h", k = 2L, distance = "dtw", clustering = "pam")

我尝试创建椭圆以将参数传递给绘图函数

test_plot <- function(dat,  ...) {
  opt <- list(...)
  color <- "red"
  if(!is.null(opt$col)) {  # tried it with both "col" and col
    message(paste("I have col:", opt$col))
    color <- opt$col
  }
  plot(dat, col = color)
}

最后是绘制群集及其中间方法的命令

test_plot(clust.hier.disc1.clust1, type = "sc", clus = 1L)

当我运行上述命令时,默认情况下将绘制树状图(红色),而不是时间序列。有人可以告诉我如何更改线型和颜色参数吗?

0 个答案:

没有答案