Repository navigation
Expand file tree
/
Copy pathdotPlot.PathEnrich.Visual
More file actions
59 lines (52 loc) · 1.88 KB
/
Copy pathdotPlot.PathEnrich.Visual
File metadata and controls
59 lines (52 loc) · 1.88 KB
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
<- function(enrichmentResultFile = myEnrichmentDF, x = "GeneRatio", color = "pvalue",
showCategory=10, size=NULL, split = NULL,
font.size=12, title = "Dot plot", orderBy="GeneRatio", decreasing=TRUE){
library(enrichplot)
library(ggplot2)
library(DOSE)
library(data.table)
colorBy <- match.arg(color, c("pvalue", "p.adjust"))
# ------------ This code-snippet can be used for further flexibilty
if (x == "geneRatio" || x == "GeneRatio") {
x <- "GeneRatio"
if (is.null(size))
size <- "Count"
} else if (x == "count" || x == "Count") {
x <- "Count"
if (is.null(size))
size <- "GeneRatio"
} else if (is(x, "formula")) {
x <- as.character(x)[2]
if (is.null(size))
size <- "Count"
} else {
## message("invalid x, setting to 'GeneRatio' by default")
## x <- "GeneRatio"
## size <- "Count"
if (is.null(size))
size <- "Count"
}
# Read the data
df = fread(enrichmentResultFile) %>% as.data.frame()
# df <- dplyr::mutate(df, GeneRatio = eval(parse(text=GeneRatio)))
# print(paste0(df$GeneRatio))
idx <- order(df[[orderBy]], decreasing = decreasing)
df$Description <- factor(df$Description, levels=rev(unique(df$Description[idx])))
# plot the graph
p <- ggplot(df, aes_string(x=x, y="Description", size=size, color=colorBy)) +
geom_point() +
scale_color_continuous(low="red", high="blue", name = color, guide=guide_colorbar(reverse=TRUE)) +
# scale_color_gradientn(name = color, colors=sig_palette, guide=guide_colorbar(reverse=TRUE)) +
ylab(NULL) + ggtitle(title) + theme_dose(font.size) + scale_size(range=c(3, 8))
#
# ggsave(
# paste0("cnetPlot_", title, ".pdf"),
# p,
# path = "Data/PathEnrichResults/" ,
# device = "pdf",
# limitsize = F,
# width = 20,
# height = 20
# )
return(p)
}