[d06c2b]: / c_VisualizationScript / Visulz_bulkRNA_GO.R

Download this file

61 lines (45 with data), 1.6 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
# MESSAGE -----------------------------------------------------------------
#
# author: Yulin Lyu
# email: lvyulin@pku.edu.cn
#
# require: R whatever
#
# ---
# 1. Load packages --------------------------------------------------------
setwd("exampleData/RNA")
# grammar
library(tidyverse)
library(magrittr)
library(glue)
library(data.table)
# analysis
library(DESeq2)
library(org.Hs.eg.db)
library(clusterProfiler)
# graphics
library(ggplot2)
library(ggsci)
library(latex2exp)
library(patchwork)
# 2. Load data ------------------------------------------------------------
GOfile <- list.files("mid", "GO.csv", full.names = T)[1:2]
# 3. Plot -----------------------------------------------------------------
GOdata <- map(GOfile, ~ fread(.x)) %>% set_names(str_remove_all(GOfile, "mid/|.GO.*"))
plotData <- GOdata %>% imap(~ {.x[pvalue < 0.05 & Count >= 5][1:20][, type := .y]})
plotData %<>% map(~ {.x[, p := -log10(pvalue)]})
usedCol <- pal_nejm()(2)[2:1]
GOplot <- pmap(list(plotData, names(plotData), usedCol), function(x, y, z) {
ggplot(x, aes(x = p, y = fct_reorder(Description, p))) +
geom_col(aes(alpha = p), fill = z, width = .8, show.legend = F) +
scale_alpha_continuous(range = c(.5, 1)) +
scale_x_continuous(expand = expansion(c(0, 0.05))) +
labs(x = TeX("$-log_{10}(\\textit{P}\\,value)$"), y = "", title = y) +
theme(
aspect.ratio = 0.75,
panel.background = element_blank(),
panel.grid = element_blank(),
axis.line = element_line())
})
purrr::reduce(GOplot, `+`) + plot_layout(ncol = 1)
ggsave("plot/GO.pdf", width = 10, height = 3 * length(GOfile))