首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R矩阵与共现分析

R矩阵与共现分析
EN

Stack Overflow用户
提问于 2013-10-01 21:12:08
回答 1查看 1.8K关注 0票数 1

我真的是R的新手,我想用它来进行微生物类群的共现分析。我有这样一张桌子(分隔标签),里面有相对丰富的分类群:

代码语言:javascript
复制
Taxon Sample1 Sample2 Sample3.......Sample54
OTU1    0.2     0.005   0.009         0.12
OTU2    0.62.....
OTU3
....
OTU136

我想得到分类群的Spearman秩相关矩阵,然后把它绘制成一个很好的图表。在运行corr.test命令之前,我必须将表转换成矩阵,对吗?所以,我试着转换它,它没有给我任何错误,但当我尝试图腾corr.test,它说,矩阵不是数字.

有人能帮我弄清楚怎么做吗?

谢谢弗朗西丝卡

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-02 18:37:01

我刚刚想好了该怎么做,所以我给出了自己问题的答案,希望它对其他人有用:

代码语言:javascript
复制
    require(gplots)  # for heatmap.2()

    mydata <- read.csv(file="otu_tab_L4.txt", header=T, row.names=1, sep="\t")

    #transposes it and makes a matrix
    mydata_t <- t(as.matrix(mydata))

    #makes Spearman's correlation
    cor.matrix <- cor(mydata_t, method = "spearman")

    #remove upper part of the matrix, since it gives the same informations 
    cor.matrix[upper.tri(cor.matrix )] <- NA

    #checks matrix dimensions
    dim(cor.matrix)

    #Finally, I plotted a triangular heatmap of my matrix
    ##the standard function will put the y labels on the right!! I wanted them on the         left! So ##changed the heatmap.2 function code in this way:

    ####open the code:
    fix(heatmap.2)

    ###modify it in this way:
    ##when it says: " axis(4, iy, labels = labRow, las = 2, line = -0.5, tick = 0, 
     cex.axis = cexRow) "
    ##I put 2 in place of 4!! 

    heatmap<-      heatmap.2(cor.matrix,scale="none",Rowv=NA,Colv=NA,col=rainbow,margins(5,5),cexRow=0.5,cexCol=1.0,key=TRUE,keysize=1.5,trace="none")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19126026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档