R语言绘制不同颜色十六进制值的树状图
library("factoextra")
# Compute k-means with k = 3
set.seed(123)
res.km <- kmeans(scale(df[, -5]), 3, nstart = 25)
# K-means clusters showing the group of each individuals
res.km$cluster
data("USArrests")
df <- scale(USArrests)
res.hc <- eclust(df, "hclust") # compute hclust
fviz_dend(res.hc,palette = c("#BA55D3","#9370DB","#3CB371"), rect = TRUE) # dendrogam

fviz_dend(res.hc,palette = c("#7B68EE","#00FA9A","#48D1CC"), rect = TRUE) # dendrogam

library(factoextra)
USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#C71585","#191970","#000080")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#808000","#6B8E23","#FFA500")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#FF4500","#DA70D6","#98FB98")) # Visualize and cut

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#AFEEEE","#DB7093","#FFDAB9")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#CD853F","#FFC0CB","#DDA0DD")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#B0E0E6","#800080","#FF0000")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#4169E1","#8B4513","#FA8072")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#F4A460","#2E8B57","#A0522D")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#C0C0C0","#87CEEB","#6A5ACD")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#708090","#00FF7F","#4682B4")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#D2B48C","#008080","#D8BFD8")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#FF6347","#40E0D0","#EE82EE")) # Visualize and cut
# into 4 groups

USArrests %>%
scale() %>% # Scale the data
dist() %>% # Compute distance matrix
hclust(method = "ward.D2") %>% # Hierarchical clustering
fviz_dend(cex = 0.5, k = 4, palette = c("#F5DEB3","#FFFF00","#9ACD32")) # Visualize and cut
# into 4 groups

开发环境:Rubymine、RStuido与微信截屏工具
The book of Ruby----A hands-on guide for the Adventurous---[英]Huw Collingbourne---no starch press
- 点赞
- 收藏
- 关注作者
评论(0)