I am trying to draw a dendrogram from the hclust
function output. I hope the dendrogram is horizontally arranged instead of the default, which can be obtain by (for example)
require(graphics)
hc <- hclust(dist(USArrests), "ave")
plot(hc)
I tried to use as.dendrogram()
function like plot(as.dendrogram(hc.poi),horiz=TRUE)
but the result is without meaningful labels:
If I use plot(hc.poi,labels=c(...))
which is without the as.dendrogram()
, I can pass the labels=
argument, but now the dendrogram is vertical instead of horizontal. Is there a way to simultaneously arrange the dendrogram horizontally and assign user-specified labels? Thanks!
Update: as an example from the USArrests dataset, suppose I wanna use the abbreviations of the first two letters of the state names as labels, so that I wanna somehow pass labs
into the plotting function:
labs = substr(rownames(USArrests),1,2)
which gives
[1] "Al" "Al" "Ar" "Ar" "Ca" "Co" "Co" "De" "Fl" "Ge" "Ha"
[12] "Id" "Il" "In" "Io" "Ka" "Ke" "Lo" "Ma" "Ma" "Ma" "Mi"
[23] "Mi" "Mi" "Mi" "Mo" "Ne" "Ne" "Ne" "Ne" "Ne" "Ne" "No"
[34] "No" "Oh" "Ok" "Or" "Pe" "Rh" "So" "So" "Te" "Te" "Ut"
[45] "Ve" "Vi" "Wa" "We" "Wi" "Wy"
hc.poi
in your code examples? – The Red Pea