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

enter image description here

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

enter image description here

Which show the clonal frequency for each group

I don't know how to use dput() but this is my complete data


  • $\begingroup$ 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 $\endgroup$ – Exhausted Apr 8 '20 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
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(reshape2) # for melt

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

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


enter image description here

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)


I loaded your data into the dat object.

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 :

enter image description here

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.