ggplot2绘制GWAS曼哈顿图

数据长这样:

1
2
3
4
5
6
chr01;25000.0;1.8163221360895787
chr01;75000.0;2.1779931093884595
chr01;125000.0;7.688242894056851
chr01;175000.0;6.450387596899228
chr01;225000.0;7.576356589147288
chr01;275000.0;4.8746339362618425

代码:

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
# 的一个文件
readr::read_delim("./pi-per-site-acuce_windows-50000.csv", col_names = FALSE) %>%
magrittr::set_names(c("chr", "pos", "pi")) %>%
dplyr::mutate(chr = stringr::str_replace(chr, "chr", "") %>% as.numeric(),
snp = paste0(chr, pos))-> df.pi

df.pi %>%
dplyr::mutate(temp = paste0(chr, pi)) %>%
# dplyr::filter(!duplicated(temp)) %>%
dplyr::group_by(chr) %>%
dplyr::mutate(chr.len = max(pos)) %>% # 染色体长度
dplyr::ungroup() %>%
dplyr::mutate(total = cumsum(chr.len) - chr.len) %>% # 每条染色体起始位置
dplyr::arrange(chr, pos) %>%
dplyr::mutate(cum = pos + total) %>%
dplyr::mutate(new.pi = -log2(pi)) %>%
dplyr::mutate(rs = paste0(chr, pos)) %>%
dplyr::mutate(chr = stringr::str_replace(chr, "chr", "") %>% as.numeric())-> df

df %>%
group_by(chr) %>%
summarize(center=(max(cum) + min(cum) ) / 2) -> X_axis

df %>%
ggplot(aes(cum, pi)) +
geom_jitter(aes(color = as.factor(chr))) +
labs(x = "Chromosome", y = "π", title = "pi-per-site-acuce_windows-50000") +
scale_color_manual(values = rep(c("#00A087FF", "#3C5488FF"), 6)) +
scale_x_continuous( label = X_axis$chr, breaks= X_axis$center) +
scale_y_continuous(expand = c(0, 0), limits = c(0,250), breaks = seq(0, 250,50)) +
pac4xiang::mytheme_cn() +
theme(legend.position = "none") -> p.3a.1

图:

image-20231221191649833


ggplot2绘制GWAS曼哈顿图
https://lixiang117423.github.io/article/manhattan/
作者
李详【Xiang LI】
发布于
2023年12月21日
许可协议