Menu
  • HOME
  • TAGS

pheatmap in R. How to get clusters

r,pheatmap

Grab the result of pheatmap and use cutree. To extract 10 clusters e.g. you could do: library(pheatmap) res <- pheatmap(mtcars) mtcars.clust <- cbind(mtcars, cluster = cutree(res$tree_row, k = 10)) head(mtcars.clust) # mpg cyl disp hp drat wt qsec vs am gear carb cluster # Mazda RX4 21.0 6 160 110...

How can I get the new order of column and row in a heatmap after clusting using the pheatmap

r,cluster-analysis,pheatmap

I get the answer myself. test = matrix(rnorm(200), 20, 10) test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3 test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2 test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4 colnames(test) = paste("Test", 1:10, sep = "")...

Discontionous heatmap in R

r,heatmap,pheatmap

The second one is a hexbin plot If your (x,y) pairs are unique, you can do an x y plot, if that's what you want, you can try using base R plot functions: x <- runif(100) y<-runif(100) time<-runif(100) pal <- colorRampPalette(c('white','black')) #cut creates 10 breaks and classify all the values...

R - Extract (p)heatmap colors to use in polygon fill

r,polygon,heatmap,fill,pheatmap

To understand how this works, I had to look into the code of pheatmap. Let's first generate a matrix: A <- matrix(1:10, 2, 5) The default palette is defined as pal <- colorRampPalette(rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu")))(100) The idea is then to define break values and assign a color...