我正在尝试用%相似度替换树状图上的高度轴。我当前的代码是:
ABf.x<-as.matrix(ABflip)
hc<-hclust(dist(ABf.x),method="ward")
plot(hc,hang=-1,labels=ABf.x[,1])
plot(hc,main="", hang=-1,ylab="Similarity",axes=FALSE,labels=ABf.x[,1])
scale=seq(0,max(hc$height),by=10)
sequence<-as.integer(seq(1,max(hc$height)),by=10)
percent<-as.integer((sequence/max(hc$height)*100))
lines(x = c(0,0), y = c(0,max(hc$height)),type = "n")
axis(2,at=scale, labels=percent)
绘图电流没有刻度,给出错误:
Error in axis(2, at = scale, labels = percent) : 'at' and 'labels' lengths differ, 36 != 351
最佳答案
使用 iris 数据集作为示例数据。您可以使用秤将其最高设置为 100,而不是 99
ABf.x<-as.matrix(iris)
hc<-hclust(dist(ABf.x),method="ward")
plot(hc,hang=-1,labels=ABf.x[,1])
plot(hc,main="", hang=-1,ylab="Similarity",axes=FALSE,labels=ABf.x[,1])
scale=seq(0, max(hc$height), by=10)
sequence<-as.integer(seq(1,(max(hc$height)), by=10)) #get sequence of heights from dendrogram
percent<-as.integer((sequence/max(hc$height)*100)) #Convert these to a percent of the maximum height
lines(x = c(0,0), y = c(0,max(hc$height)),type = "n")
axis(2,at=scale, labels=percent)
结果链接:example
关于r - 如何在树状图的 y 轴上输出相似度百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29707672/