使用 R 中层次聚类的实际值绘制 y 轴
plot y-axis with the actual value from the hierarchical clustering in R
我正在尝试通过 Complete Linkage Method
在 R 中绘制树状图。
我将数据设置为:
x1,x2,x3,x4,x5
0,0.5,2.24,3.35,3
0.5,0,2.5,3.61,3.04
2.24,2.5,0,1.12,1.41
3.35,3.61,1.12,0,1.5
3,3.04,1.41,1.5,0
到目前为止,我已经尝试了下面的这段代码并得到了如图所示的输出:
dt <- read.csv("cluster.csv")
df<-scale(dt(-1))
dc<-dist(df,method = "euclidean")
hc1 <- hclust(dc, method = "complete" )
plot(hc1, labels = NULL, hang = 0.1,
main = "Cluster dendrogram", sub = NULL,
xlab = NULL, ylab = "Height")
现在我想
用从生成的值的实际值绘制 y 轴
簇间成对距离的计算
用 x1,x2,x3,x4,x5 绘制 x 轴
我在学习 R 时遇到问题,如何使用 plot 绘制图形。
编辑:
如答案中所述,我已将 labels
编辑为
labels = c("x1", "x2","x3","x4","x5")
得到的输出为:
现在,我想将 y 轴标记为计算高度的值
您可以访问以下值
dt <- read.csv("cluster.csv")
df<-scale(dt[-1]) # I had to use brackets here instead of parenthesis
dc<-dist(df,method = "euclidean")
hc1 <- hclust(dc, method = "complete" )
plot(hc1, labels = NULL, hang = 0.1,
main = "Cluster dendrogram", sub = NULL,
xlab = NULL, ylab = "Height")
str(hc1)
Returns:
List of 7
$ merge : int [1:4, 1:2] -1 -3 -5 1 -2 -4 2 3
$ height : num [1:4] 0.444 1.516 1.851 3.753
$ order : int [1:5] 1 2 5 3 4
$ labels : NULL
$ method : chr "complete"
$ call : language hclust(d = dc, method = "complete")
$ dist.method: chr "euclidean"
- attr(*, "class")= chr "hclust"
如您所见,没有包含五个值的向量,您需要将其直接映射到绘图中的 labels
。如果您知道如何计算这些值,只需将它们放入 five-element 向量并将其放在 labels =
之后,替换当前的 NULL
.
我正在尝试通过 Complete Linkage Method
在 R 中绘制树状图。
我将数据设置为:
x1,x2,x3,x4,x5
0,0.5,2.24,3.35,3
0.5,0,2.5,3.61,3.04
2.24,2.5,0,1.12,1.41
3.35,3.61,1.12,0,1.5
3,3.04,1.41,1.5,0
到目前为止,我已经尝试了下面的这段代码并得到了如图所示的输出:
dt <- read.csv("cluster.csv")
df<-scale(dt(-1))
dc<-dist(df,method = "euclidean")
hc1 <- hclust(dc, method = "complete" )
plot(hc1, labels = NULL, hang = 0.1,
main = "Cluster dendrogram", sub = NULL,
xlab = NULL, ylab = "Height")
现在我想
用从生成的值的实际值绘制 y 轴 簇间成对距离的计算
用 x1,x2,x3,x4,x5 绘制 x 轴
我在学习 R 时遇到问题,如何使用 plot 绘制图形。
编辑:
如答案中所述,我已将 labels
编辑为
labels = c("x1", "x2","x3","x4","x5")
得到的输出为:
现在,我想将 y 轴标记为计算高度的值
您可以访问以下值
dt <- read.csv("cluster.csv")
df<-scale(dt[-1]) # I had to use brackets here instead of parenthesis
dc<-dist(df,method = "euclidean")
hc1 <- hclust(dc, method = "complete" )
plot(hc1, labels = NULL, hang = 0.1,
main = "Cluster dendrogram", sub = NULL,
xlab = NULL, ylab = "Height")
str(hc1)
Returns:
List of 7
$ merge : int [1:4, 1:2] -1 -3 -5 1 -2 -4 2 3
$ height : num [1:4] 0.444 1.516 1.851 3.753
$ order : int [1:5] 1 2 5 3 4
$ labels : NULL
$ method : chr "complete"
$ call : language hclust(d = dc, method = "complete")
$ dist.method: chr "euclidean"
- attr(*, "class")= chr "hclust"
如您所见,没有包含五个值的向量,您需要将其直接映射到绘图中的 labels
。如果您知道如何计算这些值,只需将它们放入 five-element 向量并将其放在 labels =
之后,替换当前的 NULL
.