Heatmap in R studio
- Fortune Fornax
- Jun 11, 2020
- 1 min read
Heatmap is a graphical representation for data with different magnitude that is illustrated by colors. Here, we have used a cervical cancer data for visualization of heatmap.
install.packages("gplots") #uploads heatmap function
library("gplots")
dim(cervical_cancer) #dimension(dim) tells us the number of
rows and columns (117 143 in this case)
c_cancer <- as.matrix(cervical_cancer[, c(2:143)])
*For heatmap we want data in form of matrix to represent the values
therefore we create c_cancer using function as.matrix selecting from 2nd column to 143
heatmap.2 (c_cancer,
scale = "row", #used for normalization of data in rows
trace = "none", #removes trace lines from heatmap
Colv = NA) #removes dendrogram from columns

Changing Color Palette
library("RColorBrewer")
color_palette <- colorRampPalette(brewer.pal(8, "YlGn")
#here 8 is the number of colors with Yellow and Green (YlGn) colors
library("gplots")
dim(cervical_cancer)
c_cancer <- as.matrix(cervical_cancer [, c(2:143)])
heatmap.2(c_cancer,
scale = "row",
trace = "none",
col = color_palette, #changing color palette
main = "Heatmap")

Komentáře