a b/c_VisualizationScript/Visulz_bulkATAC_peakAnnoDisp.R
1
2
# MESSAGE -----------------------------------------------------------------
3
#
4
# author: Yulin Lyu
5
# email: lvyulin@pku.edu.cn
6
#
7
# require: R whatever
8
#
9
# ---
10
11
# * 1. Load packages ------------------------------------------------------
12
13
setwd("exampleData/ATAC")
14
15
# grammar
16
library(tidyverse)
17
library(magrittr)
18
library(glue)
19
library(data.table)
20
library(GenomicRanges)
21
22
# graphics
23
library(ggplot2)
24
library(ggchicklet)
25
library(ggsci)
26
library(scales)
27
28
# * 2. Load data ----------------------------------------------------------
29
30
peakAnnoList <- readRDS("peakAnnoList.rds")
31
32
# * 3. Plot ---------------------------------------------------------------
33
34
plotData <- imap(peakAnnoList, ~ {as.data.table(.x@anno)[, group := .y][, .(annotation, group)]}) %>% purrr::reduce(rbind)
35
36
plotData[str_detect(annotation, "Exon"), annotation := "Exon"]
37
plotData[str_detect(annotation, "Intron"), annotation := "Intron"]
38
plotData[str_detect(annotation, "Downstream|Intergenic"), annotation := "Intergenic"]
39
plotData <- plotData[, .N, by = .(annotation, group)]
40
41
ggplot(plotData, aes(x = group, y = N)) +
42
  geom_chicklet(aes(fill = fct_rev(annotation)), position = "fill", width = .95) +
43
  scale_fill_nejm() +
44
  scale_y_continuous(expand = c(0, 0)) +
45
  coord_flip() +
46
  labs(x = "", y = "") +
47
  theme(
48
    aspect.ratio = .5,
49
    panel.background = element_blank(),
50
    panel.grid = element_blank(),
51
    axis.line = element_line(),
52
    legend.title = element_blank()
53
  )
54
55
ggsave("graphics/peakAnnoDisp.png", width = 5, height = 2.5)