Create a Heatmap in R Programming – heatmap() Function

heatmap() function in R Language is used to plot a heatmap. Heatmap is defined as a graphical representation of data using colors to visualize the value of the matrix. In this to represent more common values or higher activities brighter colors basically 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

Return: This function draws a heatmap.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Set seed for reproducibility
set.seed(110) 
  
# Create example data
data <- matrix(rnorm(100, 0, 5), nrow = 10, ncol = 10) 
  
# Column names
colnames(data) <- paste0("col", 1:10)
rownames(data) <- paste0("row", 1:10)   
  
# Draw a heatmap
heatmap(data)        

chevron_right


Output:

Here, in above example number of rows and columns are specified to draw heatmap with a given function.

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Set seed for reproducibility
set.seed(110)   
  
# Create example data        
data <- matrix(rnorm(100, 0, 5), nrow = 10, ncol = 10)   
  
# Column names       
colnames(data) <- paste0("col", 1:10)
rownames(data) <- paste0("row", 1:10)   
  
# Remove dendogram
# Manual color range
my_colors <- colorRampPalette(c("cyan", "darkgreen")) 
  
# Heatmap with manual colors
heatmap(data, col = my_colors(100))                             

chevron_right


Output:

In the above example heat map is drawn by using colorRampPalette to merge two different colors.




My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.