2014-04-15 59 views
0

我想提出一個熱地圖上的矩陣:熱圖中的R錯誤

library(ggplot2) 
library(RColorBrewer) 
library(gplots) 

data <- read.csv("C://Users//TestHeatMap/test.csv",sep=",",header= TRUE) 
rnames <- data[,1] 
    mat_data <- data.matrix(data[,2:ncol(data)]) 
rownames(mat_data) <- rnames 
mat_data 

這裏是mat_data樣子:

   var1  var2  var3  var4 
meas 1 0.7305017 0.06576355 0.3570861 0.5359282 
meas2 0.3403525 0.35159679 0.2881559 0.2078828 
meas 3 0.4292799 0.02639957 0.7336405 0.6969559 
meas 4 0.4345162 0.91674849 0.8345379 0.4165677 
meas 5 0.2000233 0.21788421 0.7484787 0.8300173 
meas 6 0.1365909 0.96092637 0.5466718 0.8219013 
meas 7 0.2752694 0.25753156 0.7471216 0.1959987 
meas 8 0.5394913 0.64510271 0.4484584 0.9255199 
meas 9 0.8634208 0.55507594 0.1108058 0.1642815 
meas 10 0.9111965 0.60704937 0.3522915 0.7832306 


my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299) 
col_breaks = c(seq(-1,0,length=100), # for red 
      seq(0,0.8,length=100), # for yellow 
      seq(0.8,1,length=100)) # for green 

row_distance = dist(mat_data, method = "manhattan") 
row_cluster = hclust(row_distance, method = "ward") 
col_distance = dist(t(mat_data), method = "manhattan") 
col_cluster = hclust(col_distance, method = "ward") 


heatmap.2(mat_data, 
     cellnote = mat_data, # same data set for cell labels 
     main = "Correlation", # heat map title 
     notecol="black",  # change font color of cell labels to black 
     density.info="none", # turns off density plot inside color legend 
     trace="none",   # turns off trace lines inside the heat map 
     margins =c(12,9),  # widens margins around plot 
     col=my_palette,  # use on color palette defined earlier 
     breaks=col_breaks, # enable color transition at specified limits 
     dendrogram="none",  # only draw a row dendrogram 
     Colv="NA", 
     key = TRUE, 
     keysize = 1, 
#The 2 lines below cause an error 
# the default sorting of of the measurement10 then meansurement10 then measurement8,,, 
#i want to sort to be measurment1, then meansurement2...measurement3 etc...so I do the 2   
#lines below 
     Rowv = as.dendrogram(row_cluster), # apply default clustering method 
     Colv = as.dendrogram(col_cluster) # apply default clustering method 
     )   # turn off column clustering 

我得到的錯誤是:

Error in heatmap.2(mat_data, cellnote = mat_data, main = "Correlation", : 
    formal argument "Colv" matched by multiple actual arguments 

回答

0

這是什麼意思是heatmap.2看到兩個名字以「Colv」開頭的參數。您不能將兩個不同的值分配給Colv - 因此要麼刪除「NA」或「as.dendogram」分配。

我會仔細重讀幫助文件,以確保您正在分配正確的東西。