-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.R
66 lines (51 loc) · 1.78 KB
/
Code.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
#install.packages("remotes")
#remotes::install_github("norment/normentR")
library(tidyverse)
library(ggtext)
library(normentR)
#THE "gwas_data.csv" IS JUST A DEMO TO SHOW HOW TO PREPARE THE DATA SET
gwas_data_load <- read.csv("gwas_data.csv")
head(gwas_data_load, n=10)
sig_data <- gwas_data_load %>%
subset(p < 0.05)
notsig_data <- gwas_data_load %>%
subset(p >= 0.05) %>%
group_by(chr) %>%
sample_frac(0.1)
gwas_data <- bind_rows(sig_data, notsig_data)
data_cum <- gwas_data %>%
group_by(chr) %>%
summarise(max_bp = max(bp)) %>%
mutate(bp_add = lag(cumsum(max_bp), default = 0)) %>%
select(chr, bp_add)
gwas_data <- gwas_data %>%
inner_join(data_cum, by = "chr") %>%
mutate(bp_cum = bp + bp_add)
axis_set <- gwas_data %>%
group_by(chr) %>%
summarize(center = mean(bp_cum))
ylim <- gwas_data %>%
filter(p == min(p)) %>%
mutate(ylim = abs(floor(log10(p))) + 2) %>%
pull(ylim)
sig <- 5e-8
manhplot <- ggplot(gwas_data, aes(x = bp_cum, y = -log10(p),
color = as_factor(chr), size = -log10(p))) +
geom_hline(yintercept = -log10(sig), color = "grey40", linetype = "dashed") +
geom_point(alpha = 0.75) +
scale_x_continuous(label = axis_set$chr, breaks = axis_set$center) +
scale_y_continuous(expand = c(0,0), limits = c(0, ylim)) +
scale_color_manual(values = rep(c("#276FBF", "#183059"),
unique(length(axis_set$chr)))) +
scale_size_continuous(range = c(0.5,3)) +
labs(x = NULL,
y = "-log<sub>10</sub>(p)") +
theme_minimal() +
theme(
legend.position = "none",
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.title.y = element_markdown(),
axis.text.x = element_text(angle = 60, size = 8, vjust = 0.5)
)
print(manhplot)