# How to visualise the proportion of clonal genes to sub clonal genes [duplicate]

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

• 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 Apr 8, 2020 at 13:19

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 :

• 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 Apr 8, 2020 at 15:58
• @Exhausted Ah, then your question is not on generating a heatmap. It is "how to compute the proportion of clonal to subclonal genes"
– RoB
Apr 8, 2020 at 16:01
• @Exhausted See my updated post
– RoB
Apr 8, 2020 at 16:30