I have a boolean matrix of mutated or non mutated genes across some samples
> head(muts)
TP53 CDKN2A TSHZ3 ARID1A EPHA3 NOTCH1 ACVR2A ARID1B ARID2
LP6008336-DNA_G01 1 1 1 0 0 0 0 0 0
LP6008460-DNA_D01 1 1 0 1 0 0 0 0 0
LP6005500-DNA_D03 1 1 0 0 0 0 0 0 0
LP6008334-DNA_B02 1 0 1 0 0 0 0 0 0
LP6008334-DNA_A04 1 0 1 0 0 0 0 0 0
LP6005334-DNA_H01 1 0 0 0 1 0 0 1 0
By this code
pw_rt = data.frame(
gene = c('PIK3CA', 'EGFR', 'ERBB2', 'PTEN'),
pw = c('RTK'),
stringsAsFactors = F
)
pw_cc = data.frame(
gene = c('CDKN2A', 'CCNE1'),
pw = c('Cell Cycle'),
stringsAsFactors = F
)
pw = rbind(pw_rt, pw_cc)
pw_col = RColorBrewer::brewer.pal(n = 3, name = 'Set1')[1:2]
names(pw_col) = unique(pw$pw)
require(dplyr)
lmuts = reshape2::melt(muts) %>% as_tibble()
colnames(lmuts) = c('sample', 'gene', 'value')
pw_n = pw$pw
names(pw_n) = pw$gene
Np = nrow(muts)
lmuts %>%
mutate(gene = paste(gene), PW = pw_n[gene]) %>%
group_by(gene, PW) %>%
summarise(N = sum(value == 1)) %>%
ungroup() %>%
mutate(
PW = ifelse(is.na(PW), "None", PW),
N = paste0(N, ' (', round(N/Np * 100, 1), '%)')
) %>%
ggplot(aes(x = PW, y = gene, fill = PW)) +
geom_tile() +
geom_text(aes(label = N)) +
theme_light() +
theme(legend.position = 'bottom') +
guides(fill = guide_legend('Pathway')) +
scale_fill_manual(values = c(pw_col, `None` = 'gainsboro')) +
scale_x_discrete(limits = c(names(pw_col), 'None')) +
labs(
x = "",
y = 'Gene',
title = "Occurrence of mutations"
)
I am able to get proportion of altered pathway by these genes like
However I want to highlight oncogenes and tumour suppressors within this plot
For instance TP53 is a tumour suppressor and CCNE1 is an oncogene
I don't know how to manipulate the above code to highlight or partition genes to tumour suppressor or oncogene
Can you help?
EDITED
I have add extra column to lmuts like
> head(lmuts)
sample gene value gene_class
1 LP6005690-DNA_H02 TP53 1 TSG
2 LP2000333-DNA_A01 TP53 1 TSG
3 LP6005409-DNA_D03 TP53 1 TSG
4 LP6008141-DNA_H02 TP53 1 TSG
5 LP6008336-DNA_E02 TP53 1 TSG
6 LP6008269-DNA_B06 TP53 1 TSG
>
but
> lmuts %>%
+ mutate(gene = paste(gene), PW = pw_n[gene]) %>%
+ group_by(gene, PW) %>%
+ summarise(N = sum(value == 1)) %>%
+ ungroup() %>%
+ mutate(
+ PW = ifelse(is.na(PW), "None", PW),
+ N = paste0(N, ' (', round(N/Np * 100, 1), '%)')
+ ) %>%
+ ggplot(aes(x = PW, y = gene, fill = PW)) +
+ geom_tile() +
+ geom_text(aes(label = N)) +
+ theme_light() +
+ theme(legend.position = 'bottom') +
+ guides(fill = guide_legend('Pathway')) +
+ scale_fill_manual(values = c(pw_col, `None` = 'gainsboro')) +
+ scale_x_discrete(limits = c(names(pw_col), 'None')) +
+ labs(
+ x = "",
+ y = 'Gene',
+ title = "Occurrence of mutations"
+ )+facet_wrap(~gene_class, ncol=1)
Error: At least one layer must contain all faceting variables: `gene_class`.
* Plot is missing `gene_class`
* Layer 1 is missing `gene_class`
* Layer 2 is missing `gene_class`
Run `rlang::last_error()` to see where the error occurred.