Add line graph using anno_lines to ComplexHeatmap

46 Views Asked by At

I have the following matrices in R:

aaa = structure(c(0.587261707289144, 0.0447519987355918, 0.944631132297218, 
0.449251724407077, 0.156094168080017, 0.565523694967851, 0.87239173729904, 
0.0630774884484708, 0.956771788187325, 0.861393495928496, 0.521775238914415, 
0.837759975111112, 0.720968827139586, 0.997738079633564, 0.728970452910289, 
0.500443265307695, 0.883679241407663, 0.191160295158625, 0.195222557755187, 
0.0644529743585736, 0.814795149257407, 0.700661842245609, 0.0437303748913109, 
0.919525969773531, 0.98109476827085, 0.815997053403407, 0.283884674310684, 
0.450914195971563, 0.375928787747398, 0.0604146493133157, 0.602138079935685, 
0.327772701624781, 0.105592788429931, 0.000862989109009504, 0.396315816557035, 
0.330656992737204, 0.524514493532479, 0.383261796785519, 0.366940511157736, 
0.0185418513137847, 0.978632669663057, 0.549540873151273, 0.0369880928192288, 
0.513983499025926, 0.458033801056445, 0.510194669244811, 0.880770508665591, 
0.0488149069715291, 0.20153110078536, 0.0521715050563216, 0.444744392298162, 
0.123503080802038, 0.974009131081402, 0.122821776662022, 0.0309266704134643, 
0.493814098648727, 0.210814630845562, 0.429555207490921, 0.115378999151289, 
0.281808399129659, 0.735496113775298, 0.280034978874028, 0.193209844408557, 
0.0915995517279953, 0.680038196034729, 0.254332811804488, 0.259202382527292, 
0.148989144945517, 0.439386218320578, 0.665370191447437, 0.804060532012954, 
0.926760265836492, 0.554486082866788, 0.662159540457651, 0.0261470004916191, 
0.905036554438993, 0.296018165303394, 0.316355613758788, 0.762261205352843, 
0.0897036017850041, 0.968567726202309, 0.834296024637297, 0.132462466368452, 
0.120841359719634, 0.409581739688292, 0.110954186413437, 0.467486419249326, 
0.778558735735714, 0.231911435723305, 0.387052305275574, 0.0833887453190982, 
0.185123172355816, 0.967027444159612, 0.682988477405161, 0.93034086143598, 
0.591044887900352, 0.0797453178092837, 0.8450185675174, 0.0297843723092228, 
0.814659719588235), dim = c(10L, 10L), dimnames = list(c("R1", 
"R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10"), c("C1", 
"C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10")))
bbb
structure(c(0.390749461017549, 0.143404533853754, 0.666557763237506, 
0.618586165364832, 0.448763228487223, 0.806599612580612, 0.870606883428991, 
0.98618273017928, 0.40263657621108, 0.352131931111217, 0.121898651123047, 
0.990613096160814, 0.935729715740308, 0.939029850531369, 0.407482102513313, 
0.772180330008268, 0.388215313199908, 0.032627907814458, 0.396214288892224, 
0.958923527505249, 0.522330810083076, 0.673792657442391, 0.0102066865656525, 
0.505596571369097, 0.752790449652821, 0.451706958236173, 0.7646165760234, 
0.562582415761426, 0.735405725659803, 0.730329097248614, 0.3404902133625, 
0.69749222882092, 0.539553300710395, 0.878918587230146, 0.0756559933070093, 
0.376636961940676, 0.640494304243475, 0.0253231811802834, 0.206948393490165, 
0.63380507635884), dim = c(10L, 4L), dimnames = list(c("R1", 
"R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10"), c("Stage1", 
"Stage2", "Stage3", "Stage4")))

I am in the process of assembling a Heatmap with a series of line graphs associated with it as a row annotation. I have gotten this far:

row_ha = rowAnnotation(log2FC = anno_points(bbb, width = unit(4, "cm")))
stage_heatmap = Heatmap(aaa,
                        name = "log2FoldChange",
                        column_names_side = "bottom",
                        column_title_side = "top",
                        column_names_centered = TRUE,
                        row_names_side = "right",
                        row_title_side = "left",
                        right_annotation = row_ha,
                        km = 2,
                        row_names_gp = gpar(fontfamily = "sans", fontsize = 12),
                        row_title_gp = gpar(fontfamily = "sans", fontsize = 18),
                        cluster_rows = T, cluster_columns = F,
                        na_col = "#000000",
                        column_title_gp = gpar(fontfamily = "sans", fontsize = 18),
                        column_names_gp = gpar(fontfamily = "sans", fontsize = 18),
                        column_names_rot = 0,
                        row_gap = unit(2.5, "mm"),
                        show_row_names = F,
                        show_column_names = T,
                        row_title_rot = 0,
                        border = T,
                        heatmap_legend_param = list(title_gp = gpar(fontfamily = "sans", fontface= "bold", fontsize = 20),
                                                    labels_gp = gpar(fontfamily = "sans", fontsize = 18), 
                                                    border = "#000000",
                                                    direction = "horizontal",
                                                    title_position = "topcenter",
                                                    legend_width = unit(3.5, "cm")),
                        column_gap = unit(1, "cm"),
                        col = colorRamp2(c(0, .5, 1), colors = c("#0000FF", "#FFFF00", "#FF0000")))

I would like to make a heat map with a row annotation that has a line graph that has values for each of the Stages in the bbb matrix. I can make the heat map but it is not using the column names as values on the x-axis.

0

There are 0 best solutions below