0

I am currently a beginner at learning how to make a heatmap on R using data stored in excel sheets, However i have managed to make a simple heatmap so far but i wanted to know how can i display metadata above the heatmap as shown in the attached image in which metadata is being displayed in the form of colored boxes above the heatmap. i want to know whether i am supposed to make two separate excel sheets to display the data or a single one? it would be really great if i get a sample excel sheet showing display values for metadata and a heatmap along with the code that can be used? Thank you !

1 Answers1

0

Here is a similar example with pheatmap. You will have to read the documentation and understand the options to make it suitable to your data.

# generate some example data
dta <- matrix(sample(0:2, 50, replace = TRUE), nrow=5)
rownames(dta) <- letters[1:5]
colnames(dta) <- LETTERS[1:10]

# prepare a data frame with the annotation
ann_df <- data.frame(row.names = colnames(dta),
                     Region = rep(c("first", "second"), times = c(3,7)),
                     Phylogroup = rep(c("A1", "B2"), times=5))

# plot the heatmap itself
pheatmap::pheatmap(dta,
                   color = c("grey", "pink", "brown"),
                   scale = "none",
                   cluster_rows = FALSE,
                   cluster_cols = TRUE,
                   cutree_cols = 3,
                   annotation_col = ann_df)
Alexlok
  • 2,999
  • 15
  • 20
  • hey @Alexlok can you please help me with the excel sheet preparation or do you have any proper tutorial for making that sort of heatmap. Actually i am a Biological Sciences student so i don't know the deep basics of R or coding , however your guidance regarding this will be so helpful – Quratulain Farooq Aug 05 '20 at 19:34
  • I'm afraid that requires some more learning about R. I think the first chapters of this book are clear and should give you the tools required: https://r4ds.had.co.nz/data-import.html . The short version is save your Excel as csv, read it in R with readr::read_csv, then format it as a matrix and put it in pheatmap. But each step may depend on what your data actually looks like. – Alexlok Aug 05 '20 at 19:49