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
![](https://static.wixstatic.com/media/56e222_3a282f82f3354e58ad2834f2cc2b8b17~mv2.png/v1/fill/w_704,h_409,al_c,q_85,enc_auto/56e222_3a282f82f3354e58ad2834f2cc2b8b17~mv2.png)
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")
![](https://static.wixstatic.com/media/56e222_c04e5f2294f341b78b1521e854997a24~mv2.png/v1/fill/w_704,h_409,al_c,q_85,enc_auto/56e222_c04e5f2294f341b78b1521e854997a24~mv2.png)
Comments