R语言绘制不同颜色十六进制值的树状图

临风暖阳 发表于 2022/11/15 16:02:38 2022/11/15
【摘要】 笔者根据不同颜色十六进制值使用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


【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区),文章链接,文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:cloudbbs@huaweicloud.com进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。