Monday 8 July 2019

Heatmaps and R

Ages ago I wrote a blogpost on heatmaps in R, but that was focussing mainly on clustering and dendrograms.

This week I wanted to draw a simple heatmap and found nice tutorial here.

My input data looks something like this (in file 'mydata'):
,cell1,cell2,cell3
gene1,10,12,8
gene2,33,35,11
gene3,44,32,45
gene4,322,234,1343

To make a heatmap I did this:
> data <- read.csv("mydata")
> rnames <- data[,1]
> mat_data <- data.matrix(data[,2:ncol(data)])
> rownames(mat_data) <- rnames
> my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299)
> library(gplots)
> heatmap.2(mat_data,trace="none",col=my_palette, dendrogram="none", margins=c(12,9))






This gives a nice heatmap like this: