-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_webgestalt.R
96 lines (81 loc) · 3.61 KB
/
plot_webgestalt.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
##' .. content for \description{} (no empty lines) ..
##'
##' .. content for \details{} ..
##'
##' @title
##' @param webgestalt_results
##' @return
##' @author whtns
##' @export
plot_webgestalt <- function(webgestalt_results) {
make_volcano_plot <- function(webgestalt_results, showpath = TRUE, ...) {
# browser()
mytheme <- theme_classic(base_size = 20)
webgestalt_results <-
webgestalt_results %>%
dplyr::mutate(neglogFDR = -log10(FDR)) %>%
dplyr::mutate(description = str_wrap(description, 16)) %>%
dplyr::mutate(description = paste0(description, "\n", geneSet)) %>%
dplyr::arrange(geneSet, desc(variants))
label_data <- webgestalt_results %>%
dplyr::group_by(geneSet) %>%
dplyr::filter(row_number() == 2)
path_plot <- function(path){
list(
if (showpath)
geom_path(arrow = arrow(angle = 15, type = "closed"))
)
}
volcano_plot <-
webgestalt_results %>%
ggplot(aes(x = enrichmentRatio, y = neglogFDR, group = geneSet)) +
geom_point(aes(color = variants), size = 6) +
path_plot(path) +
geom_label_repel(data = label_data,
mapping = aes(
x = enrichmentRatio,
y = neglogFDR,
label = description
),
size = 4,
min.segment.length = 0.2,
segment.alpha = 1,
point.padding = 8e-1,
box.padding = 5,
force = 2,
nudge_x = 8,
na.rm = TRUE
) +
labs(y = "-log(10) FDR", x = "Enrichment Ratio") +
geom_hline(yintercept = -log10(0.1), linetype="dashed") +
mytheme +
# guides(color = guide_legend(override.aes = list(Title = ""))) +
scale_color_hue(labels = c("nonsynonymous coding \n+ synonymous + non-coding", "\nnonsynonymous coding")) +
# scale_y_log10(breaks = 10^seq(-15, 0, by = 2), limits = c(1e-15, 1e0)) +
theme(legend.title=element_blank())
return(volcano_plot)
}
cell_line_genesets <-
webgestalt_results %>%
dplyr::filter(variant_set == "Cell Line")
tumor_genesets <-
webgestalt_results %>%
dplyr::filter(variant_set == "Tumor")
tumor_volcano_plot <-
tumor_genesets %>%
make_volcano_plot()+
scale_x_continuous(breaks = seq(0, 35, by = 5), limits = c(0, 35)) +
theme(legend.position = c(0.5, 0.8),
legend.background = element_rect(color = "black", linetype="dashed")) +
# theme(legend.background = element_rect(color = "black", linetype="dashed")) +
scale_y_continuous(limits = c(0, 12), breaks = 0:12, minor_breaks = seq(0, 12, 0.5), expand = expansion(add = 0.5)) +
NULL
cell_line_volcano_plot <-
cell_line_genesets %>%
make_volcano_plot(showpath = TRUE) +
scale_x_continuous(breaks = seq(20, 120, by = 20), limits = c(20, 120)) +
scale_y_continuous(limits = c(0, 5), breaks = 0:5, minor_breaks = seq(0, 5, 0.5), expand = expansion(add = 0.5)) +
guides(color="none") +
NULL
list(tumor = tumor_volcano_plot, cell_line = cell_line_volcano_plot)
}