Search code examples
rgplots

ColSideColors key for heatmap.2 function R


I have gone through the documentation of the heatmap.2() function in the gplots package in R looking for a way to code a color key for the ColSideColors argument. Is this supported? I would like to show which levels are represented by each color on the output plot.


Solution

  • legend function in R can help use to solving this problem.

    The code just looks like this:

    heatmap.2(mydata,ColSideColors=mycolors)
    # ploting a heatmap
    legend("left", title = "Tissues",legend=c("group1","group2"), 
           fill=c("red","green"), cex=0.8, box.lty=0)
    # add a legend in which put your group text in legend, 
    # and pass your colors which is used in heatmap.2 to fill.
    

    You can get help in this tutorial