Home > Blockchain >  pheatmap with larger gap_col in R
pheatmap with larger gap_col in R

Time:09-22

In R function pheatmap::pheatmap, is it possible to adjust the gap distances?


In the following example, I created a gap in columns 3 and 4 using parameter gaps_col=3. Yet, the gap is too small visually. I wonder if there is a way to adjust the gap size? At this moment, I do not consider using other packages.

# Create test matrix
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 = "")
rownames(test) = paste("Gene", 1:20, sep = "")

# Draw heatmaps
pheatmap(test, cluster_cols = F, gaps_col = 3) # creating gap using gaps_col. 

CodePudding user response:

You could do this by saying multiple times the same gaps_col for example three times column 3 as a vector like this:

library(pheatmap)
# Create test matrix
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 = "")
rownames(test) = paste("Gene", 1:20, sep = "")

# Draw heatmaps
pheatmap(test, cluster_cols = F, gaps_col = c(3, 3, 3))

Created on 2022-09-21 with reprex v2.0.2

6 times:

# Draw heatmaps
pheatmap(test, cluster_cols = F, gaps_col = c(3, 3, 3, 3, 3, 3))

Created on 2022-09-21 with reprex v2.0.2

  • Related