R错误中的热图

时间:2014-04-15 19:58:52

标签: 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

1 个答案:

答案 0 :(得分:0)

这意味着heatmap.2看到两个名称以&#34; Colv&#34;开头的参数。 。您无法为Colv分配两个不同的值 - 因此要么删除teh&#34; NA&#34;或者&#34; as.dendogram&#34;分配

我会仔细阅读帮助文件,以确保您分配正确的内容。