R - Phylogram labels to vector

南笙酒味 提交于 2019-12-11 03:37:17

问题


If we plot a phylogram from hierarchical clustering using ape package

phy <- hclust(dist(mtcars))
plot(as.phylo(phy),direction="downwards")

Is there a way to extract the labels in to a vector in the same order they appear in the phylogram (read from left to right)?

If I try

phy$labels

I can get the labels out but they appear to be in a different order.


回答1:


Using the additional order component, you can get them in the proper ordering

with(phy, labels[order])
# [1] "Maserati Bora"       "Chrysler Imperial"   "Cadillac Fleetwood" 
#  [4] "Lincoln Continental" "Ford Pantera L"      "Duster 360"         
#  [7] "Camaro Z28"          "Hornet Sportabout"   "Pontiac Firebird"   
# [10] "Hornet 4 Drive"      "Valiant"             "Merc 450SLC"        
# ... 


来源:https://stackoverflow.com/questions/31933994/r-phylogram-labels-to-vector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!