美文网首页
ggplot2聚类

ggplot2聚类

作者: 可能性之兽 | 来源:发表于2023-10-20 16:28 被阅读0次
clusters <- hclust(dist(USArrests), "ave")

# reshaping USArrests
df <- data.frame(
  State = rownames(USArrests)[row(USArrests)],
  variable = colnames(USArrests)[col(USArrests)],
  value = unname(do.call(c, USArrests))
)

g <- ggplot(df, aes(variable, State, fill = value)) +
  geom_raster()
g + scale_y_dendrogram(hclust = clusters)
image.png

Position Guides • ggh4x --- • ggh4x (teunbrand.github.io)

相关文章

网友评论

      本文标题:ggplot2聚类

      本文链接:https://www.haomeiwen.com/subject/eyvkidtx.html