简体   繁体   中英

Heat Map in R error

I want to put a heat map on a matrix:

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

Here is what mat_data looks like:

             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

The error I am getting is:

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

What that means is that heatmap.2 sees two arguments whose name begins with "Colv" . You can't assign two different values to Colv - so either delete teh "NA" or the "as.dendogram" assignment.

I'd reread the help file carefully to be sure you're assigning the right things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM