r - 如何在树状图的 y 轴上输出相似度百分比?

标签 r

我正在尝试用%相似度替换树状图上的高度轴。我当前的代码是:

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/

相关文章:

r - 在kernlab中的SVM训练之外的内核矩阵计算

r - 如何将 Leaflet.Locate 添加到 R 制作的 map (而不是定位)

r - 在 R 中将两组向量相乘

r - 数据表 (DT) Shiny R - 选择所有找到的行

r - R-x 中的 Wilcoxon 检验必须是数字错误

r - 如何将双矩阵转换为数据框列

r - 如何在 R [xts] 中绘制某些列?

r - 将图像转换为黑白以在 R 中进行图像识别

r - 替代deparse()的更快方法

r - ggtitle : remove extra spaces and add a new line in ggplot title 中的粘贴函数