<p>While it was easy to get your data after your edit, the data was not quite useful, the second data frame/matrix has 2 columns only!</p>

<p>I had to create a fake data set, that looks like this:</p>

<pre><code>my_df &lt;- data.frame(
  gene_class = rep(letters[1:4],3),
  some_value = rep(1:3*10,4)
)
rownames(my_df) &lt;- paste("Gene-",rep(LETTERS[1:4],each = 3),1:4,sep="")

&gt; my_df
        gene_class some_value
Gene-A1          a         10
Gene-A2          b         20
Gene-A3          c         30
Gene-B4          d         10
Gene-B1          a         20
Gene-B2          b         30
Gene-C3          c         10
Gene-C4          d         20
Gene-C1          a         30
Gene-D2          b         10
Gene-D3          c         20
Gene-D4          d         30
</code></pre>

<p>Using the <code>ComplexHeatmap</code> package, I got something similar to the figure you have posted.</p>

<pre><code># data frame for annotation
my_annot &lt;- my_df[,"gene_class",drop=FALSE]

# the Heatmap() function requires a matrix
my_matrix &lt;- as.matrix(my_df[,"some_value",drop=FALSE])

dev.off() # clear the plotting area in case not empty
ha = rowAnnotation(gene_class = my_annot$gene_class)

ht &lt;-  Heatmap(my_matrix,
               left_annotation = ha, # gene_class
               row_names_side = "left", # position of row (gene) names
               heatmap_width = unit(0.3, "cm")*nrow(my_matrix), # cell width
               cluster_rows = FALSE, # no clustering
               cluster_columns = FALSE, # no clustering
               cell_fun = function(j, i, x, y, w, h, col) { # add text ("some value column") to each grid
                 grid.text(my_matrix[i, j], x, y)
               })
draw(ht, heatmap_legend_side = "bottom")
</code></pre>

<p>The <code>ComplexHeatmap</code> package offers enormous flexibility for customization. I strongly recommend devoting some time to it. The way I use it, I try to put all of my data/information in a single data frame/table, which I subsequently subset to create data frames and matrices for annotations and the actual heatmap(s) respectively.</p>

<p><a href="https://i.sstatic.net/8md20.png" rel="noreferrer"><img src="https://i.sstatic.net/8md20.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2020-04-15T13:50:52.723Z
Thank you @haci . You are amazing and helpful as always, definitely your solution works but I don't know how to format my own data to work with your code. What you have produced is what I need as long as I am able to adapt my data our your dummy input
Zizogolu
CC BY-SA 4.0
2020-04-14T11:57:45.027Z
2020-04-14T11:57:45.027Z
haci
<p>I wish to reproduce a very informative plot in google </p>

<p><a href="https://i.sstatic.net/qQ9IF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qQ9IF.png" alt="enter image description here"></a></p>

<p>Given a group of samples and a list of genes for which we have data how each genes has mutated and whether the alleles are homozygous of heterozygous. These are expressed as boolean values</p>

<p>Genes enriched in 2 pathways like cell cycle and p53 as shown in this figure</p>

<p>Map of functional alterations for a group of patients. Genes (rows) encoding components p53–DNA repair pathway;  are affected by selected functional events (percent of samples altered and types of alteration are represented by colored squares) across group of samples in column. Alterations of the pathway are observed stacked green bar plots at bottom</p>

<p>I have the boolean matrix of mutated genes per sample would be grateful for assistence.</p>

<p>An example of my copy number data</p>

<pre><code>&gt; dataset_gistic$annotations
     type                event     
G2   "Homozygous Deletion"   "ACVR2A"  
G13  "Homozygous Deletion"   "HIST1H3B"
G73  "Heterozygous Deletion" "CCNE1"   
G74  "Heterozygous Deletion" "TSHZ3"   
G78  "Low-level Amplification"    "CTNNB1"
G110 "Low-level Amplification"    "CCNE1"   
G111 "Low-level Amplification"    "TSHZ3"   
G119 "High-level Amplification"   "PIK3CA"  
G121 "High-level Amplification"   "NIPBL"     
G147 "High-level Amplification"   "CCNE1"   
G148 "High-level Amplification"   "TSHZ3"   
&gt;

&gt; dput(dataset_gistic$annotations)
structure(c("Homozygous Loss", "Homozygous Loss", "Homozygous Loss", 
"Homozygous Loss", "Homozygous Loss", "Homozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "High-level Gain", "High-level Gain", "High-level Gain", 
"High-level Gain", "High-level Gain", "High-level Gain", "High-level Gain", 
"High-level Gain", "High-level Gain", "High-level Gain", "High-level Gain", 
"High-level Gain", "ACVR2A", "HIST1H3B", "CDKN2A", "PTEN", "NAV3", 
"LIN7A", "ARID1A", "ACVR2A", "SCN3A", "CTNNB1", "PBRM1", "EPHA3", 
"POLQ", "PIK3CA", "SLIT2", "NIPBL", "MSH3", "APC", "HIST1H3B", 
"ARID1B", "CDKN2A", "NOTCH1", "PTEN", "CCND1", "KRAS", "LRRK2", 
"ARID2", "NAV3", "LIN7A", "SIN3A", "TP53", "ERBB2", "GPATCH8", 
"RNF43", "GATA6", "SMAD4", "CCDC102B", "STK11", "SMARCA4", "CCNE1", 
"TSHZ3", "CTNNB1", "PIK3CA", "SLIT2", "NIPBL", "HIST1H3B", "ARID1B", 
"EGFR", "KCNQ3", "NOTCH1", "PTEN", "CCND1", "KRAS", "LRRK2", 
"ARID2", "SIN3A", "ERBB2", "GPATCH8", "RNF43", "GATA6", "CCDC102B", 
"STK11", "SMARCA4", "CCNE1", "TSHZ3", "PIK3CA", "NIPBL", "EGFR", 
"KCNQ3", "CCND1", "KRAS", "ERBB2", "GPATCH8", "RNF43", "GATA6", 
"CCNE1", "TSHZ3"), .Dim = c(77L, 2L), .Dimnames = list(c("G2", 
"G13", "G17", "G19", "G24", "G25", "G38", "G39", "G40", "G41", 
"G42", "G43", "G44", "G45", "G46", "G47", "G48", "G49", "G50", 
"G51", "G54", "G55", "G56", "G57", "G58", "G59", "G60", "G61", 
"G62", "G63", "G64", "G65", "G66", "G67", "G68", "G69", "G70", 
"G71", "G72", "G73", "G74", "G78", "G82", "G83", "G84", "G87", 
"G88", "G89", "G90", "G92", "G93", "G94", "G95", "G96", "G97", 
"G100", "G102", "G103", "G104", "G105", "G107", "G108", "G109", 
"G110", "G111", "G119", "G121", "G126", "G127", "G131", "G132", 
"G139", "G140", "G141", "G142", "G147", "G148"), c("type", "event"
)))
&gt; 
</code></pre>

<p>And this is sample of my mutational data the number of mutations for each gene in each sample</p>

<pre><code>    om$numericMatrix
       LP6005500-DNA_D03 LP6008336-DNA_G01 LP6008460-DNA_D01 LP6005334-DNA_H01
TP53                   2                 2                 2                 2
CDKN2A                 3                 1                 2                 0
       LP6007600 LP6008334-DNA_A03 LP6008334-DNA_A04 LP6008334-DNA_B02
TP53           2                 2                 2                 2
CDKN2A         0                 0                 0                 0
       LP6008334-DNA_C02 LP6008334-DNA_D02 LP6008336-DNA_H01 LP6008337-DNA_A07
TP53                   2                 1                 2                 2
CDKN2A                 0                 0                 0                 0
       LP6008337-DNA_H06 LP6008460-DNA_A04
TP53                   2                 2
CDKN2A                 0                 0
&gt; 

&gt; dput(om$numericMatrix)
structure(c(2, 3, 2, 1, 2, 2, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 
0, 1, 0, 2, 0, 2, 0, 2, 0, 2, 0), .Dim = c(2L, 14L), .Dimnames = list(
    c("TP53", "CDKN2A"), c("LP6005500-DNA_D03", "LP6008336-DNA_G01", 
    "LP6008460-DNA_D01", "LP6005334-DNA_H01", "LP6007600", "LP6008334-DNA_A03", 
    "LP6008334-DNA_A04", "LP6008334-DNA_B02", "LP6008334-DNA_C02", 
    "LP6008334-DNA_D02", "LP6008336-DNA_H01", "LP6008337-DNA_A07", 
    "LP6008337-DNA_H06", "LP6008460-DNA_A04")))
&gt; 
</code></pre>

CC BY-SA 4.0
2020-04-13T22:16:17.703Z
Why unvoting? Do you think only by a simple googling one can get such a plot?
Zizogolu
CC BY-SA 4.0
2020-04-13T22:46:07.867Z
Can you update the question by giving an example of your data looks like instead of describing them by words?
Phoenix Mu
CC BY-SA 4.0
2020-04-14T06:56:17.617Z
@Exhausted, please provide the community with a reproducible example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example As was suggested in another question of yours, `dput()` will help us "reproduce" your input data. If you invest a couple of minutes going through the link and subsequently increase the "quality" and "completeness" of your questions, you will get answers much faster you do now.
haci
<r><heatmap><figure-reproduction>
Is it possible to get such a plot
# Is it possible to get such a plot

(Asked by: username_0 on 2020-04-13)

I wish to reproduce a very informative plot in google 

Given a group of samples and a list of genes for which we have data how each genes has mutated and whether the alleles are homozygous of heterozygous. These are expressed as boolean values
Genes enriched in 2 pathways like cell cycle and p53 as shown in this figure
Map of functional alterations for a group of patients. Genes (rows) encoding components p53–DNA repair pathway;  are affected by selected functional events (percent of samples altered and types of alteration are represented by colored squares) across group of samples in column. Alterations of the pathway are observed stacked green bar plots at bottom
I have the boolean matrix of mutated genes per sample would be grateful for assistence.
An example of my copy number data
> dataset_gistic$annotations
     type                event     
G2   "Homozygous Deletion"   "ACVR2A"  
G13  "Homozygous Deletion"   "HIST1H3B"
G73  "Heterozygous Deletion" "CCNE1"   
G74  "Heterozygous Deletion" "TSHZ3"   
G78  "Low-level Amplification"    "CTNNB1"
G110 "Low-level Amplification"    "CCNE1"   
G111 "Low-level Amplification"    "TSHZ3"   
G119 "High-level Amplification"   "PIK3CA"  
G121 "High-level Amplification"   "NIPBL"     
G147 "High-level Amplification"   "CCNE1"   
G148 "High-level Amplification"   "TSHZ3"   
>

> dput(dataset_gistic$annotations)
structure(c("Homozygous Loss", "Homozygous Loss", "Homozygous Loss", 
"Homozygous Loss", "Homozygous Loss", "Homozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Heterozygous Loss", "Heterozygous Loss", 
"Heterozygous Loss", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "Low-level Gain", "Low-level Gain", "Low-level Gain", 
"Low-level Gain", "High-level Gain", "High-level Gain", "High-level Gain", 
"High-level Gain", "High-level Gain", "High-level Gain", "High-level Gain", 
"High-level Gain", "High-level Gain", "High-level Gain", "High-level Gain", 
"High-level Gain", "ACVR2A", "HIST1H3B", "CDKN2A", "PTEN", "NAV3", 
"LIN7A", "ARID1A", "ACVR2A", "SCN3A", "CTNNB1", "PBRM1", "EPHA3", 
"POLQ", "PIK3CA", "SLIT2", "NIPBL", "MSH3", "APC", "HIST1H3B", 
"ARID1B", "CDKN2A", "NOTCH1", "PTEN", "CCND1", "KRAS", "LRRK2", 
"ARID2", "NAV3", "LIN7A", "SIN3A", "TP53", "ERBB2", "GPATCH8", 
"RNF43", "GATA6", "SMAD4", "CCDC102B", "STK11", "SMARCA4", "CCNE1", 
"TSHZ3", "CTNNB1", "PIK3CA", "SLIT2", "NIPBL", "HIST1H3B", "ARID1B", 
"EGFR", "KCNQ3", "NOTCH1", "PTEN", "CCND1", "KRAS", "LRRK2", 
"ARID2", "SIN3A", "ERBB2", "GPATCH8", "RNF43", "GATA6", "CCDC102B", 
"STK11", "SMARCA4", "CCNE1", "TSHZ3", "PIK3CA", "NIPBL", "EGFR", 
"KCNQ3", "CCND1", "KRAS", "ERBB2", "GPATCH8", "RNF43", "GATA6", 
"CCNE1", "TSHZ3"), .Dim = c(77L, 2L), .Dimnames = list(c("G2", 
"G13", "G17", "G19", "G24", "G25", "G38", "G39", "G40", "G41", 
"G42", "G43", "G44", "G45", "G46", "G47", "G48", "G49", "G50", 
"G51", "G54", "G55", "G56", "G57", "G58", "G59", "G60", "G61", 
"G62", "G63", "G64", "G65", "G66", "G67", "G68", "G69", "G70", 
"G71", "G72", "G73", "G74", "G78", "G82", "G83", "G84", "G87", 
"G88", "G89", "G90", "G92", "G93", "G94", "G95", "G96", "G97", 
"G100", "G102", "G103", "G104", "G105", "G107", "G108", "G109", 
"G110", "G111", "G119", "G121", "G126", "G127", "G131", "G132", 
"G139", "G140", "G141", "G142", "G147", "G148"), c("type", "event"
)))
> 

And this is sample of my mutational data the number of mutations for each gene in each sample
    om$numericMatrix
       LP6005500-DNA_D03 LP6008336-DNA_G01 LP6008460-DNA_D01 LP6005334-DNA_H01
TP53                   2                 2                 2                 2
CDKN2A                 3                 1                 2                 0
       LP6007600 LP6008334-DNA_A03 LP6008334-DNA_A04 LP6008334-DNA_B02
TP53           2                 2                 2                 2
CDKN2A         0                 0                 0                 0
       LP6008334-DNA_C02 LP6008334-DNA_D02 LP6008336-DNA_H01 LP6008337-DNA_A07
TP53                   2                 1                 2                 2
CDKN2A                 0                 0                 0                 0
       LP6008337-DNA_H06 LP6008460-DNA_A04
TP53                   2                 2
CDKN2A                 0                 0
> 

> dput(om$numericMatrix)
structure(c(2, 3, 2, 1, 2, 2, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 
0, 1, 0, 2, 0, 2, 0, 2, 0, 2, 0), .Dim = c(2L, 14L), .Dimnames = list(
    c("TP53", "CDKN2A"), c("LP6005500-DNA_D03", "LP6008336-DNA_G01", 
    "LP6008460-DNA_D01", "LP6005334-DNA_H01", "LP6007600", "LP6008334-DNA_A03", 
    "LP6008334-DNA_A04", "LP6008334-DNA_B02", "LP6008334-DNA_C02", 
    "LP6008334-DNA_D02", "LP6008336-DNA_H01", "LP6008337-DNA_A07", 
    "LP6008337-DNA_H06", "LP6008460-DNA_A04")))
>

**Tags:** r, heatmap, figure-reproduction
> **Comments:**
> **username_0**: Why unvoting? Do you think only by a simple googling one can get such a plot?  
> **username_1**: Can you update the question by giving an example of your data looks like instead of describing them by words?  
> **username_2**: @Exhausted, please provide the community with a reproducible example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example As was suggested in another question of yours, `dput()` will help us "reproduce" your input data. If you invest a couple of minutes going through the link and subsequently increase the "quality" and "completeness" of your questions, you will get answers much faster you do now.  

---

## 1 answers

### Answer by username_2 on 2020-04-14. Score: 6

While it was easy to get your data after your edit, the data was not quite useful, the second data frame/matrix has 2 columns only!
I had to create a fake data set, that looks like this:
my_df <- data.frame(
  gene_class = rep(letters[1:4],3),
  some_value = rep(1:3*10,4)
)
rownames(my_df) <- paste("Gene-",rep(LETTERS[1:4],each = 3),1:4,sep="")

> my_df
        gene_class some_value
Gene-A1          a         10
Gene-A2          b         20
Gene-A3          c         30
Gene-B4          d         10
Gene-B1          a         20
Gene-B2          b         30
Gene-C3          c         10
Gene-C4          d         20
Gene-C1          a         30
Gene-D2          b         10
Gene-D3          c         20
Gene-D4          d         30

Using the ComplexHeatmap package, I got something similar to the figure you have posted.
# data frame for annotation
my_annot <- my_df[,"gene_class",drop=FALSE]

# the Heatmap() function requires a matrix
my_matrix <- as.matrix(my_df[,"some_value",drop=FALSE])

dev.off() # clear the plotting area in case not empty
ha = rowAnnotation(gene_class = my_annot$gene_class)

ht <-  Heatmap(my_matrix,
               left_annotation = ha, # gene_class
               row_names_side = "left", # position of row (gene) names
               heatmap_width = unit(0.3, "cm")*nrow(my_matrix), # cell width
               cluster_rows = FALSE, # no clustering
               cluster_columns = FALSE, # no clustering
               cell_fun = function(j, i, x, y, w, h, col) { # add text ("some value column") to each grid
                 grid.text(my_matrix[i, j], x, y)
               })
draw(ht, heatmap_legend_side = "bottom")

The ComplexHeatmap package offers enormous flexibility for customization. I strongly recommend devoting some time to it. The way I use it, I try to put all of my data/information in a single data frame/table, which I subsequently subset to create data frames and matrices for annotations and the actual heatmap(s) respectively.

> **Comments:**
> **username_0**: Thank you @haci . You are amazing and helpful as always, definitely your solution works but I don't know how to format my own data to work with your code. What you have produced is what I need as long as I am able to adapt my data our your dummy input  

---

