Search code examples
rggplot2heatmapheatmaply

Association Clusters to Heatmap


I have two seperate dataframes, from one of these I have already created a heatmap from the first dataframe, however I want to add a sidebar that indicates the type of family that a gene is actually associated to it.

Dataframe 1

BGC1     BGC2    Distance
-----------------------------------------------
BGC31     BGC34     0.6
BGC34     BGC45     0.7
BGC34     BGC53     0.2
BGC53     BGC31     0.8

Dataframe2

BGC1     Association  
----------------------------------
BGC31     Skin Cancer
BGC34     Skin Cancer     
BGC34     Lung Cancer     
BGC53     Liver Cancer

Heatmap Creation:

p3 <- heatmap.3(comat, scale = "none", trace = "none", col = color,  main="GCF Co-Occurrence Map"
                ,lhei=c(0.5,1),  keysize=0.5, cexRow = 0.60, cexCol = 0.65)

I'm looking to create something like this where each color represents a type of gene cluster associated to a specific gene class:

enter image description here


Solution

  • Look at the section "Adding annotation based on additional factors using RowSideColors" in heatmaply manual:

    https://talgalili.github.io/heatmaply/articles/heatmaply.html#adding-annotation-based-on-additional-factors-using-rowsidecolors

    x  <- as.matrix(datasets::mtcars)
    rc <- colorspace::rainbow_hcl(nrow(x))
    
    heatmaply(
      x[, -c(8, 9)],
      seriate = "mean",
      col_side_colors = c(rep(0, 5), rep(1, 4)),
      row_side_colors = x[, 8:9]
    )
    

    Outcome:

    enter image description here