我试图控制树状图的顺序和颜色。显然,dendorgram的要点是按相似性排序,但在分支内我想设置一个有意义的顺序(字母数字)。
library(vegan)
library(stats)
x <-data.frame(data = c(1:10))
y = data.frame(type = c("A","B","C","A","C","D","A","B","C","B"), site_name = c("A1","B1","C1","A2","C2","D1","A3","B2","C3","B3"))
row.names(x) = y$site_name
dis = vegdist(x)
hc <- hclust(dis)
dd <- as.dendrogram(hc)
plot(dd)
我的数据标签是文字,但它们确实有变量
中列出的设定顺序site_order = c("A1","A2","A3","B1","B2","B3","C1","C2","C3","D1")
1)我想找到一个解决方案,根据分支内的site_order
对树形图进行排序。
e.g。 A1,B1,A2,C1,C2,D2,A3,B2,B3,C3
我还想使用site_type
为标签着色和整形
例如(A =红色圆圈,B =蓝色方形,C =绿色三角形,D =黄色十字形)
这可能吗?
答案 0 :(得分:0)
这是使用dendextend中的rotate
函数最好的工作。
library(vegan)
library(stats)
x <-data.frame(data = c(1:10))
y = data.frame(type = c("A","B","C","A","C","D","A","B","C","B"), site_name = c("A1","B1","C1","A2","C2","D1","A3","B2","C3","B3"))
row.names(x) = y$site_name
dis = vegdist(x)
hc <- hclust(dis)
dd <- as.dendrogram(hc)
par(mfrow = c(1,2))
plot(dd, main = "orig")
library(dendextend)
dd2 <- rotate(dd, sort(labels(dd)) )
plot(dd2, main = "as sorted as possible \n(under the constraints)")
输出:
您可以从the online vignettes了解有关dendextend软件包的更多信息。