我正在尝试从hclust
函数输出中绘制树状图。我希望树状图是水平排列的而不是默认的,可以通过(例如)
require(graphics)
hc <- hclust(dist(USArrests), "ave")
plot(hc)
我尝试使用as.dendrogram()
类似的功能,plot(as.dendrogram(hc.poi),horiz=TRUE)
但结果没有有意义的标签:
如果我使用plot(hc.poi,labels=c(...))
which is without the as.dendrogram()
,我可以传递labels=
参数,但现在树状图是垂直的而不是水平的。有没有办法同时水平排列树状图并分配用户指定的标签?谢谢!
更新:作为 USArrests 数据集的示例,假设我想使用州名称的前两个字母的缩写作为标签,以便我想以某种方式传递labs
给绘图函数:
labs = substr(rownames(USArrests),1,2)
这使
[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"