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
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.