I'm essentially trying to change the labels of my dendrogram, to the corresponding row in the table. For instance, consider the USArrest data set.
Right now the labels on the dendrogram are just the states name, "Alabama" and so on. But looking at the data table, the row for alabama looks like this
Murder Assault UrbanPop Rape
Alabama 13.2 236 58 21.2
So instead of just "Alabama" as a label, I wish to have this full row: Alabama 13.2 236 58 21.2
and so on for all the other labels of the dendrogram.
My code looks like this:
library("ggplot2")
library("ggdendro")
library(dendextend)
data(USArrests)
dend <- USArrests %>% scale %>%
dist %>% hclust %>% as.dendrogram
dend %>% plot
dend %>% set("labels_cex", 0.8) %>% # Change size
plot(main = "Dendrogram") # plot
I tried reducing the dendrogram to only two rbanches to try to make it easier on me. So let's say I'm working with dend <- USArrests[1:2,] %>% scale %>%
I tried something like this:
alabama_label <- USArrests[1,]
alaska_label <- USArrests[2,]
dend %>% set("labels", c(alabama_label, alaska_label))
But that did not work. It only gave me the value from the USArrests[1,1]
and USArrests[2,1]
as label.
So I'm just wondering, how can i possibly label the dendrogram with all the rows?