<p>I've used some dummy data for simplicity. It's fairly easy to do this with ggplot, but you have to format your matrix-like data for ggplot input.</p>

<p>eg :</p>

<pre><code># make data
set.seed(1)
ngenes &lt;- 20
nsamps &lt;- 10
my_dat &lt;- matrix(rnorm(ngenes*nsamps), ncol = nsamps, nrow = ngenes)
colnames(my_dat) &lt;- paste("samp", seq_len(nsamps))
rownames(my_dat) &lt;- paste("gene", seq_len(ngenes))

library(ggplot2)
library(reshape2) # for melt

# format data for plotting
dat_toplot &lt;- melt(my_dat)

#plot
ggplot(dat_toplot, aes(x = Var1, y = Var2, fill = value)) + geom_tile()
</code></pre>

<p>plots</p>

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

<p>If you need specifics on plot tweaking, google's your friend. There are plenty of tutorials on how to use ggplot for heatmaps. (eg. <a href="https://learnr.wordpress.com/2010/01/26/ggplot2-quick-heatmap-plotting/" rel="nofollow noreferrer">here</a>, or <a href="https://jcoliver.github.io/learn-r/006-heatmaps.html" rel="nofollow noreferrer">here</a>)</p>

<h1>EDIT</h1>

<p>I loaded your data into the <code>dat</code> object.</p>

<pre><code>library(tidyverse)
dat &lt;- as_tibble(dat)

dat_counts &lt;- dat %&gt;% group_by(Sample, Gene) %&gt;% summarise(count_subclonal = sum(CCF&lt;1), count_clonal = sum(CCF&gt;=1))
dat_counts<span class="math-container">$ratio &lt;- dat_counts$</span>count_subclonal/dat_counts$count_clonal

# set infinite values (/0) to NA
dat_counts<span class="math-container">$ratio[is.infinite(dat_counts$</span>ratio)] &lt;- NA


ggplot(dat_counts, aes(x = Sample, y = Gene, fill = ratio)) + geom_tile() + 
  geom_text(aes(label = paste(count_subclonal, "/", count_clonal)), col = 'white') # add ratio text
</code></pre>

<p>Outputs :</p>

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

CC BY-SA 4.0
2020-04-08T15:58:58.197Z
Thank you but this is not what I need, I need the proportion of clonal to sub clonal genes in each box not a heat map of cancer cell fraction
Zizogolu
CC BY-SA 4.0
2020-04-08T16:01:58.113Z
@Exhausted Ah, then your question is not on generating a heatmap. It is "how to compute the proportion of clonal to subclonal genes"
RoB
CC BY-SA 4.0
2020-04-08T16:30:43.373Z
@Exhausted See my updated post
RoB
CC BY-SA 4.0
2020-04-08T13:46:06.977Z
2020-04-08T16:30:29.813Z
2020-04-08T16:30:29.813Z
RoB
<p>I have a data frame</p>

<pre><code>Response_TO_CHEMOTHERAPY    Gene    CCF
Responders                  POLQ    1
Responders                 CDKN2A   1
Responders                  TP53    1
Responders              CCDC102B    0.906729075
Non-responders           CCDC102B   1
Non-responders           CCDC102B   1
Non-responders           CCDC102B   1
Non-responders             TSHZ3    1
Non-responders             PIK3CA   1
Responders                 SLIT2    1
Non-responders              SLIT2   1
</code></pre>

<p>I have <code>two groups of patients</code>; <code>Responders to chemotherapy and non-responders</code>. For each group I have calculated <code>cancer cell faction (CCF)</code> for a fixed set of genes so that an individual gene has several reads in each group</p>

<p>If <code>CCF = 1</code> the gene clonal and if CCF &lt; 1 gene is sub clonal, for a given gene for each group, I therefore would have the number of clonal and sub clonal for this gene, for example 2 clonal 7 sub clonal which would be 2/7 something like the below figure</p>

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

<p>This is another potential example which reveals what is in my mind</p>

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

<p>Which show the clonal frequency for each group</p>

<p>I don't know how to use <code>dput()</code> but this is my complete data</p>

<p><a href="https://www.dropbox.com/s/ol7m4nlkuyuy85a/c1.txt?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/ol7m4nlkuyuy85a/c1.txt?dl=0</a></p>

CC BY-SA 4.0
2020-04-08T13:19:33.733Z
Sorry why you are unvoting my question? Is not it clear enough? When I am asking a question that means I need to solve that not that I am posting a question for fun. I invest time to prepare input and to know what exactly I am looking for
Zizogolu
<r><ggplot2><cnv><heatmap><complexheatmap>
How to visualise the proportion of clonal genes to sub clonal genes
# How to visualise the proportion of clonal genes to sub clonal genes

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

I have a data frame
Response_TO_CHEMOTHERAPY    Gene    CCF
Responders                  POLQ    1
Responders                 CDKN2A   1
Responders                  TP53    1
Responders              CCDC102B    0.906729075
Non-responders           CCDC102B   1
Non-responders           CCDC102B   1
Non-responders           CCDC102B   1
Non-responders             TSHZ3    1
Non-responders             PIK3CA   1
Responders                 SLIT2    1
Non-responders              SLIT2   1

I have two groups of patients; Responders to chemotherapy and non-responders. For each group I have calculated cancer cell faction (CCF) for a fixed set of genes so that an individual gene has several reads in each group
If CCF = 1 the gene clonal and if CCF < 1 gene is sub clonal, for a given gene for each group, I therefore would have the number of clonal and sub clonal for this gene, for example 2 clonal 7 sub clonal which would be 2/7 something like the below figure

This is another potential example which reveals what is in my mind

Which show the clonal frequency for each group
I don't know how to use dput() but this is my complete data
https://www.dropbox.com/s/ol7m4nlkuyuy85a/c1.txt?dl=0

**Tags:** r, ggplot2, cnv, heatmap, complexheatmap
> **Comments:**
> **username_0**: Sorry why you are unvoting my question? Is not it clear enough? When I am asking a question that means I need to solve that not that I am posting a question for fun. I invest time to prepare input and to know what exactly I am looking for  

---

## 1 answers

### Answer by username_1 on 2020-04-08. Score: 3 | Accepted answer

I've used some dummy data for simplicity. It's fairly easy to do this with ggplot, but you have to format your matrix-like data for ggplot input.
eg :
# make data
set.seed(1)
ngenes <- 20
nsamps <- 10
my_dat <- matrix(rnorm(ngenes*nsamps), ncol = nsamps, nrow = ngenes)
colnames(my_dat) <- paste("samp", seq_len(nsamps))
rownames(my_dat) <- paste("gene", seq_len(ngenes))

library(ggplot2)
library(reshape2) # for melt

# format data for plotting
dat_toplot <- melt(my_dat)

#plot
ggplot(dat_toplot, aes(x = Var1, y = Var2, fill = value)) + geom_tile()

plots

If you need specifics on plot tweaking, google's your friend. There are plenty of tutorials on how to use ggplot for heatmaps. (eg. here, or here)
EDIT
I loaded your data into the dat object.
library(tidyverse)
dat <- as_tibble(dat)

dat_counts <- dat %>% group_by(Sample, Gene) %>% summarise(count_subclonal = sum(CCF<1), count_clonal = sum(CCF>=1))
dat_counts$ratio <- dat_counts$count_subclonal/dat_counts$count_clonal

# set infinite values (/0) to NA
dat_counts$ratio[is.infinite(dat_counts$ratio)] <- NA


ggplot(dat_counts, aes(x = Sample, y = Gene, fill = ratio)) + geom_tile() + 
  geom_text(aes(label = paste(count_subclonal, "/", count_clonal)), col = 'white') # add ratio text

Outputs :

> **Comments:**
> **username_0**: Thank you but this is not what I need, I need the proportion of clonal to sub clonal genes in each box not a heat map of cancer cell fraction  
> **username_1**: @Exhausted Ah, then your question is not on generating a heatmap. It is "how to compute the proportion of clonal to subclonal genes"  
> **username_1**: @Exhausted See my updated post  

---

