2

I am giving the example data provided by hclust help:

mds2 <- -cmdscale(UScitiesD)
hcity.D <- hclust(UScitiesD, "ward.D")
plot(hcity.D,  hang=-1)

When you plot this the site labels are vertical- which is appropriate for this example since they use long names. However my data is labelled simply A1, A2, etc. and when I plot the graph it looks unnecessary to have vertical labelling.

I know that for a vertical dendrogram, las=2, and that srt = 90 can also rotate the y-axis labels in text(), but this doesn't appear to affect the labels in this hclust plot.

How can I rotate the site labels to be horizontal for this plot?

Thanks

Tal Galili
  • 24,605
  • 44
  • 129
  • 187
Birdonawire
  • 199
  • 3
  • 10

1 Answers1

1

You can solve this using the following code, just change srt to whatever you want (notice you'll need the dendextend R package):

mds2 <- -cmdscale(UScitiesD)
hcity.D <- hclust(UScitiesD, "ward.D")
dend <- as.dendrogram(hcity.D)

# install.packages("dendextend")
library(dendextend)
dend_labels <- labels(dend)
labels(dend) <- ""
plot(dend)
text(x = 1:length(dend_labels), labels = dend_labels, srt = 45, adj = c(1,1), xpd = T)

enter image description here

Tal Galili
  • 24,605
  • 44
  • 129
  • 187