Reputation: 145
I would like to change the default labels for the leaves of a dendrogram to match a categorical variable column in a dataframe generated using dplyr
group_by
and summarise
functions. This is a screenshot of the dataframe.
I would like to use the 'm' column variables as the labels for the dendrogram.
This is the code to generate the dendrogram (sfdf_lop
is the dataframe)
csfdf_lop <- hclust(dist(sfdf_lop[, -1]), method = "complete")
plot(csfdf_lop)
and the output looks like this:
How do I use the variables in the column 'm' to label the leaves, in place of the default numbered leaves?
Edit Below is the result of using the suggested code
tempdf<- as.data.frame(sfdf_lop)
row.names(tempdf)<- tempdf$m
csfdf_lop <- hclust(dist(tempdf[, -1]), method = "complete")
plot(csfdf_lop)
Upvotes: 0
Views: 1037
Reputation: 24079
If you convert your data to data.frame and define the row.names to equal column M.
tempdf<- as.data.frame(sfdf_lop)
row.names(tempdf)<- tempdf$m
csfdf_lop <- hclust(dist(tempdf[, -1]), method = "complete")
plot(csfdf_lop)
Upvotes: 1