How to make hierarchical cluster pheatmap in r?

169 Views Asked by At

I have use this code to make hierarchical cluster heatmap but no color is coming

library(tidyverse)

Mydata <- 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))

library(pheatmap)

Mydata %>% column_to_rownames(var = "Location") %>% 
 as.matrix() %>% pheatmap(Mydata, cutree_cols = 6)
1

There are 1 best solutions below

0
On

You don't need to pass data again when using pipes. Try :

library(pheatmap)
Mydata %>% 
   column_to_rownames(var = "Location") %>% 
   as.matrix() %>% pheatmap(cutree_cols = 6)

enter image description here