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 heat map

enter image description here

By your kindly code I produced this

enter image description here

Which is not well informative

This is another potential example heat map

enter image description here

Which show the clonal frequency for each group

By the way thanks for your kindness

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



Given the lack of effort from the OP, probably I shouldn't have wasted my time on this question with a lot of problems:

i) The question is not reproducible, the OP should have supplied their data with dput().

ii) The data as pasted above does not quite make sense to me, why would you have three readings from the same gene and even in such a case how should these replicates be represented in a heatmap?

iii) The question is not specific enough and should not go like "how can I generate a heatmap" and should be more like "in an attempt to generate a heatmap like in this figure I have tried this piece of code but ..."

Having said these, and after downvoting the question, here is a solution leveraging the ComplexHeatmap package:


my_data <-
Sample  Gene    CCF
Sample1 POLQ    1
Sample1 CDKN2A  1
Sample1 TP53    1
Sample1 CCDC102B    0.906729075
Sample1 CCDC102B    1
Sample1 CCDC102B    1
Sample1 CCDC102B    1
Sample2 TSHZ3   1
Sample2 PIK3CA  1
Sample2 SLIT2   1
Sample2 SLIT2   1

my_data <- fread(my_data)

my_data <- dcast.data.table(my_data, 
                            formula = Gene ~ Sample,
                            value.var = "CCF",

# dcast generates NA values as the provided data does not have values for each gene
my_data[is.na(my_data)] <- 0

# Heatmap() expects a matrix input
my_matrix <- as.matrix(my_data[,c("Sample1", "Sample2")])
rownames(my_matrix) <- my_data$Gene

        cell_fun = function(j, i, x, y, width, height, fill) {
          grid.text(my_matrix[i, j], x, y, gp = gpar(fontsize = 10))})

This is how the data look after dcast, in which multiple entries per gene (my point ii above) is summarized with mean():

> head(my_matrix)
           Sample1 Sample2
CCDC102B 0.9766823       0
CDKN2A   1.0000000       0
PIK3CA   0.0000000       1
POLQ     1.0000000       0
SLIT2    0.0000000       1
TP53     1.0000000       0

Here is the resulting heatmap:

enter image description here

  • $\begingroup$ Sorry please don't close my question, I have edited that and I am certain I know what I want and what is the final goal $\endgroup$ – Exhausted Apr 8 '20 at 9:11

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