2013-10-01 51 views
1

我真的是新手,我想用它來進行微生物分類羣的共現分析。我有一個像這樣的表(製表符分隔)與類羣的相對丰度:R矩陣和共生分析

Taxon Sample1 Sample2 Sample3.......Sample54 
OTU1 0.2  0.005 0.009   0.12 
OTU2 0.62..... 
OTU3 
.... 
OTU136 

我想獲得類羣的Spearman秩相關矩陣,然後在一些不錯的圖形繪製。我應該不得不在矩陣中轉換我的表格,然後運行corr.test命令,對嗎?所以,我試圖轉換它,它並沒有給我任何錯誤,但是當我嘗試tun corr.test時,它說該矩陣不是數字....

任何人都可以幫助我怎麼辦?

感謝 弗朗西斯

+0

這聽起來像功課,而且你還沒有在數據上顯示代碼或'str()'的輸出。 –

+0

嗨迪文!我很抱歉,我不知道論壇規則...這些是我跑的命令:> row.names(otu.tab1)< - otu_tab1 $ Taxon > row.names(otu_tab1)< - otu_tab1 $分類單元 >暗淡(otu_tab1) [1] 134 54 > otu_tab1 <-otu_tab1 [,2:54] > otu_tab1_mat <-as.matrix(otu_tab1) 這是STR()的輸出:> STR( [1:134,1:53]「0.0083825900」「0.0000000000」「0.0000000000」... ... - attr(*,「dimnames」)= 2列表中的 .. $:chr [1:134] 「Root; Other; Other; Other」「氯黴素菌; f__」「Solibacteres; f__Solibacteraceae」「Actinobacteria;其他」... .. $:chr [1:53]「NO8.4」「NO6.1」「NO7 .3「」NO9.4「... –

+2

Noooooo。編輯你的問題。請進一步閱讀使用本網站的說明。 –

回答

0

我只是想出了怎麼辦,所以我postinf回答我自己的問題,希望它可能是對他人有用:

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")