ggplot2聚类

2023-10-20  本文已影响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)

上一篇 下一篇

猜你喜欢

热点阅读