Preparing Your Data
For our demonstration, let’s consider a hypothetical gene expression dataset. It’s crucial to have data with clear patterns or relationships to create meaningful heatmaps. Replace this example data with your own dataset as needed.
R
# Example gene expression data gene_data <- data.frame ( Gene = c ( "Gene1" , "Gene2" , "Gene3" , "Gene4" , "Gene5" ), Sample1 = c (2.3, 1.8, 3.2, 0.9, 2.5), Sample2 = c (2.1, 1.7, 3.0, 1.0, 2.4), Sample3 = c (2.2, 1.9, 3.1, 0.8, 2.6), Sample4 = c (2.4, 1.6, 3.3, 0.7, 2.3), Sample5 = c (2.0, 1.5, 3.4, 0.6, 2.7) ) # Print the example gene expression data print (gene_data) |
Output:
Gene Sample1 Sample2 Sample3 Sample4 Sample5
1 Gene1 2.3 2.1 2.2 2.4 2.0
2 Gene2 1.8 1.7 1.9 1.6 1.5
3 Gene3 3.2 3.0 3.1 3.3 3.4
4 Gene4 0.9 1.0 0.8 0.7 0.6
5 Gene5 2.5 2.4 2.6 2.3 2.7
Creating Heatmaps with Hierarchical Clustering
Before diving into our actual topic, let’s have an understanding of Heatmaps and Hierarchical Clustering.