我试图用%相似度替换树形图上的高度轴。我目前的代码是:
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)
绘图电流出现时没有出现错误的比例:
轴错误(2,at = scale,labels = percent): &#39;在&#39;和&#39;标签&#39;长度不同,36!= 351
答案 0 :(得分:1)
使用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