OscarTheGrouch
OscarTheGrouch

Reputation: 2384

Simple Dendrogram in R with first data column as labels

I created a dendrogram in R with the command below...

I have been trying to find the command to replace the number with the name of the County which is the first column in the data set or load the plot with the name of the county instead of the number. If anyone could help that would be appreciated.

hc = hclust(dist(NYCounty))
plot(hc)

The current plot

The data of NYCounty

Upvotes: 0

Views: 834

Answers (1)

Vincent Bonhomme
Vincent Bonhomme

Reputation: 7453

You can pass it to labels argument in plot.hclust. A reproducible example showing this:

# example from ?hclust
hc <- hclust(dist(USArrests), "ave")
plot(hc)
# custom labels
df <- data.frame(foo=paste("hi", 1:50))
plot(hc, labels=df$foo)

Is this what you want?

Upvotes: 1

Related Questions