在 r 中绘制集群成员 [英] Plot the cluster member in r

查看:20
本文介绍了在 r 中绘制集群成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 R 中使用 DTW 包.我终于完成了层次聚类.但我想像下图一样单独绘制时间序列集群.

sc <- read.table("D:/handling data/confirm.csv", header=T, sep="," )行名(sc) <- sc$STDR_YM_CDsc$STDR_YM_CD <- NULLcol_n <- colnames(sc)hc <- hclust(dist(sc), method="average")情节(hc,主要=")

我该怎么做?我在

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 中绘制集群成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆