问题描述
我正在尝试对由科学数据产生的数据矩阵进行聚类.我知道我要如何完成聚类,但是不确定如何在R中完成这一壮举.
I am trying to cluster a data matrix produced from scientific data. I know how I want the clustering done, but am not sure how to accomplish this feat in R.
这是数据的样子:
A1 A2 A3 B1 B2 B3 C1 C2 C3
sample1 1 9 10 2 1 29 2 5 44
sample2 8 1 82 2 8 2 8 2 28
sample3 9 9 19 2 8 1 7 2 27
请考虑A1,A2,A3是一次处理的三个重复,以及B和C.Sample1是不同的测试变量.因此,我想对该矩阵进行分层聚类,以查看列之间的所有差异,特别是我将制作树状图(树)以观察列的相关性.
Please consider A1,A2,A3 to be three replicates of a single treatment, and likewise with B and C. Sample1 are different tested variables. So, I want to hierarchically cluster this matrix in order to see the over all differences between the columns, specifically I will be making a dendrogram (tree) to observe the relatedness of the columns.
有人知道如何适当地聚类这样的东西吗?我尝试这样做:
Does anyone know how to appropriately cluster something like this? I tried doing this with this:
raw.data <- read.delim("test.txt",header=FALSE,stringsAsFactors=FALSE)
dist.mat<-vegdist(raw.data,method="jaccard")
clust.res<-hclust(dist.mat)
plot(clust.res)
...但是,这导致了每个样本变量而不是每个列都有分支的树.感谢您的任何建议!
...However, this resulted in a tree with branches for each sample variable, instead of each column. Thanks for any suggestions!
推荐答案
只需转置您的数据集:
raw.data <- t(raw.data)
require(vegan)
dist.mat<-vegdist(raw.data,method="jaccard")
clust.res<-hclust(dist.mat)
plot(clust.res)
这篇关于如何在R中对数据矩阵进行分层聚类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!