ComplexHeatmap with anno_barplot
1
1
Entering edit mode
9 months ago

I've been making various heatmaps for different gene sets and I added the log2FoldChange values as an extra column, but I need to leave it as a barplot, but I've been lost on how to put those log2FoldChange values to appear as bars. Any help is appreciated, thanks ;)

ha <- HeatmapAnnotation(summary = anno_summary(gp = gpar(fill = 3), 
                                           height = unit(1, "cm")))

h1<- Heatmap(mat.scaled, cluster_rows = F, name="Z-score", cluster_columns = T, col= col_fun, width = ncol(mat.scaled)*unit(10, "mm"), height = nrow(mat.scaled)*unit(10, "mm"), show_column_names = F, show_column_dend = T, top_annotation=colAnn) 

h2 <- Heatmap(l2_val, row_labels = df.top$symbol, 
        cluster_rows = F, name="LFC", rowAnnotation = ha, col = col_logFC,
          cell_fun = function(j, i, x, y, w, h, col) { # add text to each grid
          grid.text(round(l2_val[i, j],2), x, y)
        }, rect_gp = gpar(col = "white", lwd = 0.09), width = ncol(mat.scaled)*unit(3, "mm"), height = nrow(mat.scaled)*unit(3, "mm"), show_column_names = F)

h<-h1+h2

hf<-draw(h, merge_legend = TRUE, column_dend_side = "bottom", ht_gap = unit(4.5, "mm"))

enter image description here

data:

baseMean log2FoldChange      lfcSE       stat
TRINITY_DN2981_c1_g1_i4     26.36635       6.257222 1.14626254   5.458804
TRINITY_DN973_c0_g2_i2      32.61071       2.947533 0.52482872   5.616181
TRINITY_DN46186_c0_g1_i1  1430.14501       2.730862 0.12740461  21.434559
TRINITY_DN8465_c0_g2_i1     37.13230       2.422529 0.51178737   4.733468
TRINITY_DN9419_c0_g1_i1     74.52868       1.733437 0.36643757   4.730512
TRINITY_DN1083_c0_g1_i2     37.94081       1.647859 0.53771139   3.064578
TRINITY_DN6777_c0_g4_i2     27.69262       1.600363 0.52835576   3.028951
TRINITY_DN652_c2_g1_i1     136.64937       1.222090 0.34789911   3.512773
TRINITY_DN6510_c0_g1_i2    111.16280       1.180603 0.26047578   4.532486
TRINITY_DN7412_c0_g4_i1   5949.81391       1.117412 0.09549244  11.701574
TRINITY_DN1563_c0_g1_i1    770.73847      -1.040489 0.14274078  -7.289363
TRINITY_DN6422_c0_g1_i1    760.51126      -1.269152 0.15454838  -8.212005
TRINITY_DN7939_c0_g1_i1    114.76486      -1.361774 0.26594654  -5.120479
TRINITY_DN2334_c2_g1_i2    244.69072      -1.580514 0.19002448  -8.317425
TRINITY_DN7742_c1_g4_i1   1078.44672      -1.589249 0.14274258 -11.133672
TRINITY_DN5417_c0_g1_i2     50.44834      -1.791680 0.37966640  -4.719091
TRINITY_DN1371_c0_g1_i3    584.55158      -2.228805 0.32975786  -6.758914
TRINITY_DN8762_c2_g2_i4     48.89964      -2.256699 0.39432833  -5.722894
TRINITY_DN1109_c1_g1_i1   3585.65418      -2.322378 0.09197339 -25.250536
TRINITY_DN118_c0_g1_i1   10670.24277      -2.457908 0.10578683 -23.234534
TRINITY_DN865_c1_g1_i9    1214.23519      -2.580990 0.13942780 -18.511300
TRINITY_DN16132_c0_g2_i1    22.87642      -2.655935 0.61338410  -4.329971
TRINITY_DN899_c0_g1_i2     314.85164      -2.902132 0.41458428  -7.000101
TRINITY_DN3169_c0_g1_i1   1171.46366      -3.903238 0.15413663 -25.323231
TRINITY_DN319_c0_g1_i2    3928.38869      -4.565373 0.12861494 -35.496442
                                pvalue          padj symbol
TRINITY_DN2981_c1_g1_i4   4.793529e-08  1.713703e-06 psbP_3
TRINITY_DN973_c0_g2_i2    1.952238e-08  7.375347e-07   psaA
TRINITY_DN46186_c0_g1_i1 6.363366e-102  7.767245e-99   rbcS
TRINITY_DN8465_c0_g2_i1   2.207157e-06  5.835592e-05   petB
TRINITY_DN9419_c0_g1_i1   2.239542e-06  5.915114e-05   petA
TRINITY_DN1083_c0_g1_i2   2.179771e-03  2.456542e-02   petD
TRINITY_DN6777_c0_g4_i2   2.454048e-03  2.692835e-02   atpE
TRINITY_DN652_c2_g1_i1    4.434570e-04  6.503764e-03   psbL
TRINITY_DN6510_c0_g1_i2   5.829360e-06  1.400412e-04   psbA
TRINITY_DN7412_c0_g4_i1   1.251114e-31  2.876215e-29   ChIl
TRINITY_DN1563_c0_g1_i1   3.114234e-13  2.125889e-11 LHCB_3
TRINITY_DN6422_c0_g1_i1   2.175251e-16  1.939416e-14  LHCA1
TRINITY_DN7939_c0_g1_i1   3.047603e-07  9.468996e-06 psbP_1
TRINITY_DN2334_c2_g1_i2   8.989518e-17  8.288788e-15   LHC2
TRINITY_DN7742_c1_g4_i1   8.601759e-29  1.763911e-26  TRX-F
TRINITY_DN5417_c0_g1_i2   2.369004e-06  6.218604e-05 psbP_2
TRINITY_DN1371_c0_g1_i3   1.390299e-11  7.990478e-10  LHCB1
TRINITY_DN8762_c2_g2_i4   1.047246e-08  4.110881e-07   psaL
TRINITY_DN1109_c1_g1_i1  1.117313e-140 1.975178e-137 LHCB_2
TRINITY_DN118_c0_g1_i1   2.039227e-119 3.074794e-116 LHCB_1
TRINITY_DN865_c1_g1_i9    1.674102e-76  1.362294e-73    FER
TRINITY_DN16132_c0_g2_i1  1.491292e-05  3.257887e-04   psbS
TRINITY_DN899_c0_g1_i2    2.557783e-12  1.591351e-10  ELIP2
TRINITY_DN3169_c0_g1_i1  1.772556e-141 3.245424e-138    CBR
TRINITY_DN319_c0_g1_i2   5.577636e-276 1.429715e-271 LHCSR1
HeatmapAnnotation RNA-seq ComplexHeatmap Heatmap • 655 views
ADD COMMENT
1
Entering edit mode

franciscaelibethgalvez : If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they all work. If an answer was not really helpful or did not work, provide detailed feedback so others know not to use that answer.

upvote_bookmark_accept

ADD REPLY
2
Entering edit mode
9 months ago
bk11 ★ 2.4k

You could do something like this-

set.seed(123)
library(ComplexHeatmap)

data=read.table("yourdata.txt", h=T)
head(data)
ID   baseMean log2FoldChange     lfcSE      stat    pvalue     padj symbol
TRINITY_DN2981_c1_g1_i4   26.36635       6.257222 1.1462625  5.458804  4.79e-08 1.71e-06 psbP_3
TRINITY_DN973_c0_g2_i2   32.61071       2.947533 0.5248287  5.616181  1.95e-08 7.38e-07   psaA
TRINITY_DN46186_c0_g1_i1 1430.14501       2.730862 0.1274046 21.434559 6.36e-102 7.77e-99   rbcS
TRINITY_DN8465_c0_g2_i1   37.13230       2.422529 0.5117874  4.733468  2.21e-06 5.84e-05   petB
TRINITY_DN9419_c0_g1_i1   74.52868       1.733437 0.3664376  4.730512  2.24e-06 5.92e-05   petA
TRINITY_DN1083_c0_g1_i2   37.94081       1.647859 0.5377114  3.064578  2.18e-03 2.46e-02   petD

mat = matrix(rnorm(150), 25) #I created a data matrix bases on dimension of your data
rownames(mat) = c(data$symbol)
head(mat)
row_ha=rowAnnotation(log2FC=anno_barplot(c(data$log2FoldChange)))
Heatmap(mat, name = "mat", right_annotation = row_ha, cluster_rows = FALSE)

enter image description here

And if you want expression bar along with boxplot, you could do something like this-

row_ha1=rowAnnotation(Expr=c(data$log2FoldChange), log2FC=anno_barplot(c(data$log2FoldChange)))
Heatmap(mat, name = "mat", right_annotation = row_ha1, cluster_rows = FALSE)

enter image description here

ADD COMMENT
0
Entering edit mode

perfect!! Thank you very much for the help, gratefulenter image description here

ADD REPLY

Login before adding your answer.

Traffic: 2996 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6