Wednesday, June 25, 2014

How to plot heatmap in R with only one column

If you've tried to plot heatmap in R with only one column you got an answer:
 `x' must have at least 2 rows and 2 columns
Trick to plot heatmap with only one column is to make a matrix with the same column twice and then to do a heatmap. Use the command cbind to bind matrix, column by column
matrix_name <- cbind (matrix_name, matrix_name)
The output will look similar to this one I created.



3 comments:

  1. Hi Milos, Do you remember me?
    I've switched to bioinfo as well!!
    Thanks a lot for the post. Very useful!
    Cheers

    ReplyDelete
  2. Hi Milos, this looks like a quick solution, and I am trying to use this, would your use heatmap2 command as - heatmap.2(as.matrix(matrix_name),density.info="histogram",col=mycol, trace='none) as it is giving me error. Thanks!

    ReplyDelete