-3

I have this data set, I want to make Hierarchical Cluster Heatmap in R. Please help me

structure(list(Location = c("Karnaphuli River", "Sangu River", "Kutubdia Channel", "Moheshkhali Channel", "Bakkhali River",  "Naf River", "St. Martin's Island", "Mean "), Cr = c(114.92,  2.75, 18.88, 27.6, 39.5, 12.8, 17.45, 33.41), Pb = c(31.29, 26.42,  52.3, 59.45, 34.65, 12.8, 9.5, 32.34), Cu = c(9.48, 54.39, 52.4, 73.28, 76.26, 19.48, 8.94, 42.03), Zn = c(66.2, 71.17, 98.7,  95.3, 127.84, 27.76, 21.78, 72.67), As = c(89.67, 9.85, 8.82, 18.54, 15.38, 7.55, 16.45, 23.75), Cd = c(1.06, 0, 0.96, 2.78, 3.12, 0.79, 0.45, 1.53)), class = "data.frame", row.names = c(NA, -8L))
Kazi
  • 67
  • 7

1 Answers1

0
library(tidyverse)
library(gplots)
#> 
#> Attaching package: 'gplots'
#> The following object is masked from 'package:stats':
#> 
#>     lowess

dat <- structure(list(Location = c("Karnaphuli River", "Sangu River", "Kutubdia Channel", "Moheshkhali Channel", "Bakkhali River",  "Naf River", "St. Martin's Island", "Mean "), Cr = c(114.92,  2.75, 18.88, 27.6, 39.5, 12.8, 17.45, 33.41), Pb = c(31.29, 26.42,  52.3, 59.45, 34.65, 12.8, 9.5, 32.34), Cu = c(9.48, 54.39, 52.4, 73.28, 76.26, 19.48, 8.94, 42.03), Zn = c(66.2, 71.17, 98.7,  95.3, 127.84, 27.76, 21.78, 72.67), As = c(89.67, 9.85, 8.82, 18.54, 15.38, 7.55, 16.45, 23.75), Cd = c(1.06, 0, 0.96, 2.78, 3.12, 0.79, 0.45, 1.53)), class = "data.frame", row.names = c(NA, -8L))

dat %>% 
  column_to_rownames(var = "Location") %>% 
  as.matrix() %>% 
  heatmap.2(., # source data
            scale = "none", # set scaling by column, row or none
            Rowv = T, # toggles clustering of rows
            Colv = T, # toggles clustering of columns
            trace = "none", # turn off trace in each column of heatmap
            margin = c(3, 10), # set margins around plot
            col = colorRampPalette(c("white", "red"))(11), # set color scheme
            symkey = F, # set color scale to be asymetric
            symbreaks = F, # set color scale to be asymetric
            main = "Heatmap Title", # set main plot title
            cexRow = 1, # set font size for rows
            cexCol = 1,  # set font size for columns
            tracecol = "black", # set color of histogram on key
            key.xlab = "Value", # set title for legend
            lhei = c(1,3), # set key height as proportion to total plot height
            lwid = c(1,3), # set key width as proportion to total plot width
            keysize = 2 # set overall key size
  )

Created on 2021-04-21 by the reprex package (v1.0.0)

There are many options to customize the details of the heatmap - check the documentation for more. I've shown a few of the ones I commonly use here.

Dan Adams
  • 4,971
  • 9
  • 28