Hi !
I am trying to add labels to row block annotations in pheatmap. I have the following code:
# load libraries
library("pheatmap")
# create example dataset
bins <- sample(c(1:27,50), size = 500, replace = TRUE)
list1 <- runif(500,-10,10)
list2 <- runif(500,-10,10)
dataset <- data.frame(bins, list1, list2)
dataset <- dataset[order(dataset$bins, -dataset$list1),]
# generate a vector of cumulative bincode sizes
row_gaps <- data.frame(cumsum(table(as.numeric(dataset$bins))))
# generate heatmap
pheatmap(
# data
as.matrix(dataset[2:3]), annotation_row = dataset[1],
# clustering options
scale = "none", cluster_rows = FALSE, cluster_cols = FALSE,
# drawing options
legend = TRUE, legend_labels = c("10","5","0","-5","-10"),
annotation_legend = FALSE, gaps_row = row_gaps[,1],
show_colnames = TRUE, angle_col = 0, show_rownames = FALSE, display_numbers = FALSE
)
Which gives the following output:
I would like to produce something like this:
Lists are fold changes in gene expression. Rows (genes) are divided into blocks corresponding to 'bin' identifiers. Row blocks may vary in size from one dataset to another, and numbering may not be continuous. Due to the small size of some blocks, I feel convenient to not label all of them (otherwise the labels overlap).
I have lots of datasets to process, so the idea is to not have to set anything manually.
I tried to find my way using grid.text
, but only ended up with (very) approximate positioning of the labels.
Could someone help me there?