A heatmap() function in R Programming Language is used to plot a heatmap. A heatmap is defined as a graphical representation of data using colors to visualize the value of the matrix. It is used to represent more common values or higher activities brighter colors reddish colors are used and to less common or activity values darker colors are preferred. Heatmap is also defined by the name of the shading matrix.
Syntax:
heatmap(data)
Parameters:
- data: It represent matrix data, such as values of rows and columns
1. Create a Heatmap in R Programming Language
In this example, number of rows and columns are specified to draw heatmap with a given function.
set.seed(110)
data <- matrix(rnorm(100, 0, 5), nrow = 10, ncol = 10)
colnames(data) <- paste0("col", 1:10)
rownames(data) <- paste0("row", 1:10)
heatmap(data)
Output:

2. Create heatmap in R using colorRampPalette
In this example, heat map is drawn by using colorRampPalette to merge two different colors.
set.seed(110)
data <- matrix(rnorm(100, 0, 5), nrow = 10, ncol = 10)
colnames(data) <- paste0("col", 1:10)
rownames(data) <- paste0("row", 1:10)
my_colors <- colorRampPalette(c("cyan", "darkgreen"))
heatmap(data, col = my_colors(100))
Output:

3. Adding Title and Axis Labels to the Heatmap
In this example we give the title of the heatmap using the main argument and the xlab ,ylab arguments are used to label the x and y axes, respectively.
set.seed(110)
data <- matrix(rnorm(100, 0, 5), nrow = 10, ncol = 10)
colnames(data) <- paste0("col", 1:10)
rownames(data) <- paste0("row", 1:10)
my_colors <- colorRampPalette(c("cyan", "darkgreen"))
heatmap(data, col = my_colors(100), main = "Customized Heatmap",
xlab = "Columns", ylab = "Rows")
Output:

4. Margins Around the Heatmap Plot
In this example we plot a heatmap with specified margins around the plot using the margins argument. Here the first value (5) controls the bottom margin and the second value (10) controls the right margin.
set.seed(110)
data <- matrix(rnorm(100, 0, 5), nrow = 10, ncol = 10)
colnames(data) <- paste0("col", 1:10)
rownames(data) <- paste0("row", 1:10)
my_colors <- colorRampPalette(c("cyan", "darkgreen"))
heatmap(data, col = my_colors(100), main = "Customized Heatmap",
xlab = "Columns", ylab = "Rows", margins = c(5, 10))
Output:

5. Heatmap in R without Dendrogram
In this example we plot a heatmap without dendrograms by setting Colv = NA and Rowv = NA, which removes the hierarchical clustering and dendrogram from both rows and columns.
set.seed(110)
data <- matrix(rnorm(100, 0, 5), nrow = 10, ncol = 10)
colnames(data) <- paste0("col", 1:10)
rownames(data) <- paste0("row", 1:10)
my_colors <- colorRampPalette(c("cyan", "darkgreen"))
heatmap(data, col = my_colors(100), main = "Customized Heatmap",
xlab = "Columns", ylab = "Rows", margins = c(5, 10), Colv = NA, Rowv = NA)
Output:


