本文介绍了在r中绘制集群成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在R.
中使用DTW包,最后完成了层次化聚类。
,但我想分别绘制时间序列簇,如下图所示。
sc<-read.table( D:/处理数据/confirm.csv,header = T,sep =,)
行名(sc)<-sc $ STDR_YM_CD
sc $ STDR_YM_CD<-NULL
col_n<-名称(sc)
hc<-hclust(dist(sc),method = average)
plot(hc,main =)
我该怎么做?
我在
I use DTW package in R.and I finally finished hierarchical clustering.but I wanna plot time-series cluster separately like below picture.
sc <- read.table("D:/handling data/confirm.csv", header=T, sep="," )
rownames(sc) <- sc$STDR_YM_CD
sc$STDR_YM_CD <- NULL
col_n <- colnames(sc)
hc <- hclust(dist(sc), method="average")
plot(hc, main="")
How can I do it??My data in http://blogattach.naver.com/e772fb415a6c6ddafd1370417f96e494346a9725/20170207_141_blogfile/khm2963_1486442387926_THgZRt_csv/confirm.csv?type=attachment
解决方案
You can try this:
sc <- read.table("confirm.csv", header=T, sep="," )
rownames(sc) <- sc$STDR_YM_CD
sc$STDR_YM_CD <- NULL
col_n <- colnames(sc)
sc <- t(sc) # make sure your rows represent the time series data
id <- rownames(sc)
head(sc)
hc <- hclust(dist(sc), method="average")
plot(hc, main="")
n <- 20
sc <- cbind.data.frame(id=id, sc, cluster=cutree(hc, k = n))
library(dplyr)
library(tidyr)
library(ggplot2)
sc %>% gather(variable, value, -id, -cluster) %>%
ggplot(aes(variable, value, group=id, color=id)) + geom_line() +
facet_wrap(~cluster, scales = 'free') + guides(color=FALSE) +
theme(axis.text.x = element_text(angle=90, vjust = 0.5))
这篇关于在r中绘制集群成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!