25. 曼哈頓圖繪制
清除當(dāng)前環(huán)境中的變量
rm(list=ls())
設(shè)置工作目錄
setwd("C:/Users/Dell/Desktop/R_Plots/25manhattan/")
使用qqman包繪制曼哈頓圖
# 安裝并加載所需的R包
# install.packages("qqman")
library(qqman)
##
## For example usage please run: vignette('qqman')
##
## Citation appreciated but not required:
## Turner, S.D. qqman: an R package for visualizing GWAS results using Q-Q and manhattan plots. biorXiv DOI: 10.1101/005165 (2014).
##
# 查看內(nèi)置示例數(shù)據(jù)
head(gwasResults)
## SNP CHR BP P
## 1 rs1 1 1 0.9148060
## 2 rs2 1 2 0.9370754
## 3 rs3 1 3 0.2861395
## 4 rs4 1 4 0.8304476
## 5 rs5 1 5 0.6417455
## 6 rs6 1 6 0.5190959
# 使用manhattan函數(shù)繪制曼哈頓圖
manhattan(gwasResults)
# 調(diào)整參數(shù)
manhattan(gwasResults,
main = "Manhattan Plot", #設(shè)置主標(biāo)題
ylim = c(0, 10), #設(shè)置y軸范圍
cex = 0.6, #設(shè)置點(diǎn)的大小
cex.axis = 0.9, #設(shè)置坐標(biāo)軸字體大小
col = c("blue4", "orange3","red"), #設(shè)置散點(diǎn)的顏色
suggestiveline = F, genomewideline = F, #remove the suggestive and genome-wide significance lines
chrlabs = c(paste0("chr",c(1:20)),"P","Q") #設(shè)置x軸染色體標(biāo)簽名
)
# 提取特定染色體的數(shù)據(jù)繪圖
manhattan(subset(gwasResults, CHR == 1))
# 查看感興趣的snp信息
head(snpsOfInterest)
## [1] "rs3001" "rs3002" "rs3003" "rs3004" "rs3005" "rs3006"
# 使用highlight參數(shù)高亮感興趣的snp位點(diǎn)
manhattan(gwasResults, highlight = snpsOfInterest)
# 注釋pval超過指定閾值的snp位點(diǎn)
manhattan(gwasResults, annotatePval = 0.001, annotateTop = F)
使用CMplot包繪制曼哈頓圖
# 安裝并加載所需的R包
# install.packages("CMplot")
library(CMplot)
## Full description, Bug report, Suggestion and the latest codes:
## https://github.com/YinLiLin/R-CMplot
#加載并查看示例數(shù)據(jù)
data(pig60K)
head(pig60K)
## SNP Chromosome Position trait1 trait2 trait3
## 1 ALGA0000009 1 52297 0.7738187 0.51194318 0.51194318
## 2 ALGA0000014 1 79763 0.7738187 0.51194318 0.51194318
## 3 ALGA0000021 1 209568 0.7583016 0.98405289 0.98405289
## 4 ALGA0000022 1 292758 0.7200305 0.48887140 0.48887140
## 5 ALGA0000046 1 747831 0.9736840 0.22096836 0.22096836
## 6 ALGA0000047 1 761957 0.9174565 0.05753712 0.05753712
# 使用CMplot函數(shù)繪制曼哈頓圖
# 繪制圓形曼哈頓圖
CMplot(pig60K,plot.type="c",r=0.5,
threshold=c(0.01,0.05)/nrow(pig60K),cex = 0.5,
threshold.col = c("red","orange"), threshold.lty = c(1,2),amplify = T, cir.chr.h = 2,
signal.cex = c(2,2), signal.pch = c(19,20), signal.col=c("red","green"),outward=TRUE)
## [1] "Circular_Manhattan Plotting trait1..."
## [1] "Circular_Manhattan Plotting trait2..."
## [1] "Circular_Manhattan Plotting trait3..."
## [1] "Plots are stored in: C:/Users/Dell/Desktop/R_Plots/25manhattan"
# 繪制單性狀曼哈頓圖
CMplot(pig60K,plot.type = "m",
threshold = c(0.01,0.05)/nrow(pig60K),
threshold.col=c('grey','black'),
threshold.lty = c(1,2),threshold.lwd = c(1,1), amplify = T,
signal.cex = c(1,1), signal.pch = c(20,20),signal.col = c("red","orange"))
## [1] "Rectangular_Manhattan Plotting trait1..."
## [1] "Rectangular_Manhattan Plotting trait2..."
## [1] "Rectangular_Manhattan Plotting trait3..."
## [1] "Plots are stored in: C:/Users/Dell/Desktop/R_Plots/25manhattan"
# 繪制多性狀曼哈頓圖
CMplot(pig60K,plot.type = "m",
threshold = c(0.01,0.05)/nrow(pig60K),
threshold.col=c('grey','black'),
threshold.lty = c(1,2),threshold.lwd = c(1,1), amplify = T,
multracks = T,
signal.cex = c(1,1), signal.pch = c(20,20),signal.col = c("red","orange"))
## [1] "Multracks_Rectangular Plotting trait1..."
## [1] "Multracks_Rectangular Plotting trait2..."
## [1] "Multracks_Rectangular Plotting trait3..."
## [1] "Multraits_Rectangular Plotting..."
## [1] "Plots are stored in: C:/Users/Dell/Desktop/R_Plots/25manhattan"
sessionInfo()
## R version 3.6.0 (2019-04-26)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18363)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=Chinese (Simplified)_China.936
## [2] LC_CTYPE=Chinese (Simplified)_China.936
## [3] LC_MONETARY=Chinese (Simplified)_China.936
## [4] LC_NUMERIC=C
## [5] LC_TIME=Chinese (Simplified)_China.936
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] CMplot_3.3.3 qqman_0.1.4
##
## loaded via a namespace (and not attached):
## [1] compiler_3.6.0 magrittr_1.5 tools_3.6.0 htmltools_0.3.6
## [5] yaml_2.2.0 Rcpp_1.0.5 calibrate_1.7.2 stringi_1.4.3
## [9] rmarkdown_1.13 knitr_1.23 stringr_1.4.0 xfun_0.8
## [13] digest_0.6.20 evaluate_0.14