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)
![](https://img.haomeiwen.com/i23627621/857eef6060389073.png)