R - Heatmap for categorical variables (color by row)
1
0
Entering edit mode
2.3 years ago
Bianca ▴ 20

Hello, I have a metadata file with many categorical variables. I want to make like a heatmap (using R) so I can show my variables in a more compelling way in a slide for my students.

I tried ComplexHeatmap, but I could not get it to color each row separately.

For example (a smaller version of my metadata):

meta <- data.frame(tissue = c("liver", "liver", "heart, "heart", "lung"),
                               drug = c("PMX", "PMX", "PMX", "Ctr", "Ctr"),
                               age = c("12mo", "12mo", "6mo", "6mo", "6mo"),
                               model = c("mm10", "mm10", "mm10", "mm10", "mm10")

I would like a heatmap in which:

  • each column above (tissue, drug, age) is a row of the heatmap
  • each row would have its own legend
  • each row would have its own set of colors per factor

For example my output would be a heatmap:

  • row 1 (tissue) would have liver in green, heart in red, lung in yellow
  • row 2 (drug) would have PMX in blue and Ctr in gray
  • row3 would have 12mo in pink and 6mo in purple
  • row 4 would be all orange (mm10) If possible all rows separated by a white line, or somthing similar

Can someone please help?

Thank you!

ComplexHeatmap Heatmap R • 2.5k views
ADD COMMENT
2
Entering edit mode
2.3 years ago
Asaf 10k

Looks like you are trying to plot annotations, you can use HeatmapAnnotation to give each row its own legend and color set, just plot an empty heatmap with the annotation. See here: https://jokergoo.github.io/ComplexHeatmap-reference/book/heatmap-annotations.html

ADD COMMENT
0
Entering edit mode

Sorry, I am trying, but I cant plot an empty heatmap. It doesnt work... I am very new to R. Can you please help? Thanks

ADD REPLY
1
Entering edit mode

Sorry, you don't have to draw a heatmap at all, you can draw annotations, for instance:

ha = HeatmapAnnotation(foo = 1:10, bar = c(rep('a',5), rep('b', 5)))
draw(ha)
ADD REPLY

Login before adding your answer.

Traffic: 1947 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6