用于绘制曼哈顿图的 R 语言 CMplot 软件包
曼哈顿图本质上是一个散点图,用于显示大量非零大范围波动数值,最早应用于全基因组关联分析(GWAS)研究展示高度相关位点。它得名源于样式与曼哈顿天际线相似。
近几年,在宏基因组领域,尤其是差异OTU结合分类学结果,采用Manhattan plot展示有非常好的效果,倍受推崇。
曼哈顿图优点
大数据中,即展示数据全貌,又能快速找到目标基因或OTU,同时可知目标的具体位置和分类、显著程度等信息。绝对高端大气,而且还有内涵。
数据坐标轴介绍
以GWAS研究结果为例:
- X轴为染色体编号,且每个基因组SNP位点沿染色体序列排列;在16S扩增子或宏基因组中则为OTU按Taxonomy某一级别排序。
- Y轴为该位点相关的统计显著性P-value值,由于p-value值范围是从0-1,且越小越好,直接展示非常密集于0附近,很难区分。如何使越近0的显著数值变大,且而容易区分开,log10变换是非常好的方法,直接把关注的高显著性(Pvalue趋近零)值高位显示,远离整体,目标一目了然。
- 图中水平线一般为设定的不同显著性水平阈值,方便读出每个点的显著性水平;或只添加一条显示性阈值,高于则显著。
曼哈顿图绘制工具
散点图,自然还是R语言,ggplot2可以画的非常漂亮。这里我们介绍CMplot
包绘制曼哈顿图。
1.安装并加载所需R包
> # CMplot在CRAN上可用,因此可以使用以下R代码安装它
> install.packages("CMplot") # 安装包,如果已经安装,此行可忽略。
> library(CMplot)
CMplot中有两个示例数据集,用户可以通过以下R代码导出和查看详细信息:
> data(pig60K) #calculated p-values by MLM
> data(cattle50K) #calculated SNP effects by rrblup
> 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
> head(cattle50K)
SNP chr pos Somatic cell score Milk yield Fat percentage
1 SNP1 1 59082 0.000244361 0.000484255 0.001379210
2 SNP2 1 118164 0.000532272 0.000039800 0.000598951
3 SNP3 1 177246 0.001633058 0.000311645 0.000279427
4 SNP4 1 236328 0.001412865 0.000909370 0.001040161
5 SNP5 1 295410 0.000090700 0.002202973 0.000351394
6 SNP6 1 354493 0.000110681 0.000342628 0.000105792
作为示例数据集,前三列分别为SNPs的名称、染色体、位置,列的res为GWAS的p-value或GS/GP对性状的影响,traits的数量是无限的。注意:如果绘制SNP_Density,只需要前三列。
简单来说,前三列分别为SNP的名称,所在染色体,SNP的位置,后面每列为不同性状的P值,每个性状单独一列
CMplot不仅可以处理全基因组的关联研究结果,还可以处理SNP效应、Fst、tajima’s D等。
CMplot共有40个参数,输入?CMplot可以得到所有参数的详细功能。
常用参数解释如下:
Pmap 输入数据文件
col 设置不同染色体中点的颜色
cex 设置点的大小
pch 设置点的形状
band 设置不同染色体之间的间隔
H 设置每个圈的高度
ylim 设置y轴的范围
bin.size 设置SNP密度图中的窗口大小
cex.axis 设置坐标轴字体和标签字体的大小
plot.type 设置不同的绘图类型,可以设定为 "d", "c", "m", "q" or "b"
multracks 设置是否需要绘制多个track
r 设置圈的半径大小
xlab 设置x轴标签
ylab 设置y轴标签
outward 设置点的朝向是否向外
threshold 设置阈值并添加阈值线
threshold.col 设置阈值线的颜色
threshold.lwd 设置阈值线的宽度
threshold.lty 设置阈值线的类型
amplify 设置是否放大显著的点
signal.cex 设置显著点的大小
signal.pch 设置显著点的形状
signal.col 设置显著点的颜色
chr.labels 设置染色体的标签
chr.den.col 设置SNP密度图的颜色
cir.band 设置环状曼哈度图中不同染色体之间的间隔
cir.chr 设置是否显示染色体的边界
cir.chr.h 设置染色体边界的高度
cir.legend 设置是否显示图例
cir.legend.cex 设置图例字体的大小
cir.legend.col 设置图例的颜色
LOG10 设置是否对p-value取log10对数
conf.int.col 设置QQ图中置信区间的颜色
file.output 设置是否输出图片
file 设置输出图片的格式,可以设定为"jpg", "pdf", "tiff"
dpi 设置输出图片的分辨度
memo 设置输出图片文件的名字
2.默认绘图(分别绘制出SNP密度图,曼哈顿图,环形曼哈顿图和QQ图)
2.1. SNP密度图
> CMplot(pig60K,plot.type="d",bin.size=1e6,col=c("darkgreen", "yellow", "red"),file="jpg",memo="",dpi=300,
file.output=TRUE, verbose=TRUE)
# users can personally set the windowsize and the max of legend by:
# bin.size=1e6
# bin.max=N
# memo: add a character to the output file name.
2.2. 环形曼哈顿图
(1).全基因组关联研究(Genome-wide association study(GWAS))
>CMplot(pig60K,plot.type="c",chr.labels=paste("Chr",c(1:18,"X"),sep=""),r=0.4,cir.legend=TRUE,outward=FALSE,cir.legend.col="black",cir.chr.h=1.3,chr.den.col="black",file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE)
>CMplot(pig60K,plot.type="c",r=0.4,col=c("grey30","grey60"),chr.labels=paste("Chr",c(1:18,"X"),sep=""),threshold=c(1e-6,1e-4),cir.chr.h=1.5,amplify=TRUE,threshold.lty=c(1,2),threshold.col=c("red","blue"),signal.line=1,signal.col=c("red","green"),chr.den.col=c("darkgreen","yellow","red"),
bin.size=1e6,outward=FALSE,file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE)
#Note:
1. if signal.line=NULL, the lines that crosse circles won't be added.
2. if the length of parameter 'chr.den.col' is not equal to 1, SNP density that counts
the number of SNP within given size('bin.size') will be plotted around the circle.
(2). 基因组选择/预测(Genomic Selection/Prediction(GS/GP))
>CMplot(cattle50K,plot.type="c",LOG10=FALSE,outward=TRUE,col=matrix(c("#4DAF4A",NA,NA,"dodgerblue4","deepskyblue",NA,"dodgerblue1", "olivedrab3", "darkgoldenrod1"), nrow=3, byrow=TRUE),chr.labels=paste("Chr",c(1:29),sep=""),threshold=NULL,r=1.2,cir.chr.h=1.5,cir.legend.cex=0.5,cir.band=1,file="jpg",memo="",dpi=300,chr.den.col="black",file.output=TRUE,verbose=TRUE)
#Note:
Parameter 'col' can be either vector or matrix, if a matrix, each trait can be plotted in different colors.
2.3. Single_track Rectangular-Manhattan plot
(1) Genome-wide association study(GWAS)
>CMplot(pig60K,plot.type="m",LOG10=TRUE,threshold=NULL,chr.den.col=NULL,file="jpg",memo="",dpi=300, ,file.output=TRUE,verbose=TRUE)
> CMplot(pig60K, plot.type="m", col=c("grey30","grey60"), LOG10=TRUE, ylim=c(2,12), threshold=c(1e-6,1e-4),threshold.lty=c(1,2), threshold.lwd=c(1,1), threshold.col=c("black","grey"), amplify=TRUE,chr.den.col=NULL, signal.col=c("red","green"),signal.cex=c(1,1),signal.pch=c(19,19),file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE)
#Note:
if the ylim is setted, then CMplot will only plot the ponits which among this interval.
> CMplot(pig60K, plot.type="m", LOG10=TRUE, ylim=NULL, threshold=c(1e-6,1e-4),threshold.lty=c(1,2),threshold.lwd=c(1,1), threshold.col=c("black","grey"), amplify=TRUE,bin.size=1e6,chr.den.col=c("darkgreen", "yellow","red"),signal.col=c("red","green"),signal.cex=c(1,1),signal.pch=c(19,19),file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE)
#Note:
if the length of parameter 'chr.den.col' is bigger than 1, SNP density that counts
the number of SNP within given size('bin.size') will be plotted.
(2) Genomic Selection/Prediction(GS/GP)
> CMplot(cattle50K, plot.type="m", band=0.5, LOG10=FALSE, ylab="SNP effect",threshold=c(-0.015, 0.015),threshold.lty=2, threshold.lwd=1, threshold.col="red", amplify=FALSE, chr.den.col=NULL, file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE,cex=0.8)
#Note:
if signal.col=NULL, the significant SNPs will be plotted with original colors.
> cattle50K[,4:ncol(cattle50K)] <- apply(cattle50K[,4:ncol(cattle50K)], 2, function(x) x*sample(c(1,-1), length(x), rep=TRUE))
> CMplot(cattle50K, plot.type="m", band=0, LOG10=FALSE, ylab="Abs(SNP effect)",threshold=0.015,threshold.lty=2, threshold.lwd=1, threshold.col="red", amplify=TRUE, signal.col=NULL,chr.den.col=NULL, file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE)
#Note: Positive and negative values are acceptable.
2.4. Multi_tracks Rectangular-Manhattan plot
> CMplot(pig60K, plot.type="m", multracks=TRUE, threshold=c(1e-6,1e-4),threshold.lty=c(1,2), threshold.lwd=c(1,1), threshold.col=c("black","grey"), amplify=TRUE,bin.size=1e6, chr.den.col=c("darkgreen", "yellow", "red"), signal.col=c("red","green"),signal.cex=c(1,1),file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE)
a. all traits in separated axes:
b. all traits in a axes:
2.4. Q-Q plot
2.4.1. Single_track Q-Q plot
> CMplot(pig60K,plot.type="q",conf.int.col=NULL,box=TRUE,file="jpg",memo="",dpi=300,
,file.output=TRUE,verbose=TRUE)
2.4.2. Multi_tracks Q-Q plot
> CMplot(pig60K,plot.type="q",col=c("dodgerblue1", "olivedrab3", "darkgoldenrod1"),threshold=1e6,signal.pch=19,signal.cex=1.5,signal.col="red",conf.int.col="grey",box=FALSE,multracks=TRUE,file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE)
a. all traits in a axes:
b. all traits in separated axes:
3.参数说明
Pmap: a dataframe, at least four columns. The first column is the name of SNP, the second column is the chromosome of SNP, the third column is the position of SNP, and the remaining columns are the P-value of each trait(Note:each trait a column).
col: a vector or a matrix, if "col" equals to a vector, each circle use the same colors, it means that the same chromosome is drewed in the same color, the colors are not fixed, one, two, three or more colors can be used, if the length of the "col" is shorter than the length the chromosome, then colors will be applied circularly.
if "col" equals to a matrix, the row is the number of circles(traits), the columns are the colors that users want to use for different circles, so each circle can be plotted in different number of colors, the missing value can be replaced by NA. For example:
col=matrix(c("grey30","grey60",NA,"red","blue","green","orange",NA,NA),3,3,byrow=T).
bin.size: the size of bin for SNP_density plot.
bin.max: the max value of legend of SNP_density plot, the bin whose SNP number is bigger than 'bin.max' will be use the same color.
pch: a number, the type for the points, is the same with "pch" in <plot>.
band: a number, the space between chromosomes, the default is 1(if the band equals to 0, then there would be no space between chromosome).
cir.band: a number, the space between circles, the default is 1.
H: a number, the height for each circle, each circle represents a trait, the default is 1.
ylim: a vector, the range of Y-axis when plotting the two type of Manhattans, is the same with "ylim" in <plot>.
cex.axis: a number, controls the size of numbers of X-axis and the size of labels of circle plot.
plot.type: a character or vector, only "d", "c", "m", "q" or "b" can be used. if plot.type="d", SNP density will be plotted; if plot.type="c", only circle-Manhattan plot will be plotted; if plot.type="m",only Manhattan plot will be plotted; if plot.type="q",only Q-Q plot will be plotted;if plot.type="b", both circle-Manhattan, Manhattan and Q-Q plots will be plotted; if plot.type=c("m","q"), Both Manhattan and Q-Q plots will be plotted.
multracks: a logical,if multracks=FALSE, plotting multiple traits on multiple tracks, if it is TRUE, all Manhattan plots will be plotted in only one track.
cex: a number or a vector, the size for the points, is the same with "size" in <plot>, and if it is a vector, the first number controls the size of points in circle plot(the default is 0.5), the second number controls the size of points in Manhattan plot(the default is 1), the third number controls the size of points in Q-Q plot(the default is 1)
r: a number, the radius for the circle(the inside radius), the default is 1.
xlab: a character, the labels for x axis.
ylab: a character, the labels for y axis.
xaxs: a character, The style of axis interval calculation to be used for the x-axis. Possible values are "r", "i", "e", "s", "d". The styles are generally controlled by the range of data or xlim, if given.
yaxs: a character, The style of axis interval calculation to be used for the y-axis. See xaxs above..
outward: logical, if outward=TRUE,then all points will be plotted from inside to outside.
threshold: a number or vector, the significant threshold. For example, Bonfferoni adjustment method: threshold=0.01/nrow(Pmap). More than one significant line can be added on the plots, if threshold=0 or NULL, then the threshold line will not be added.
threshold.col: a character or vector, the colour for the line of threshold levels.
threshold.lwd: a number or vector, the width for the line of threshold levels.
threshold.lty: a number or vector, the type for the line of threshold levels.
amplify: logical, CMplot can amplify the significant points, if amplify=T, then the points greater than the minimal significant level will be highlighted, the default: amplify=TRUE.
chr.labels: a vector, the labels for the chromosomes of circle-Manhattan plot.
signal.cex: a number, if amplify=TRUE, users can set the size of significant points.
signal.pch: a number, if amplify=TRUE, users can set the shape of significant points.
signal.col: a character, if amplify=TRUE, users can set the colour of significant points, if signal.col=NULL, then the colors of significant points will not be changed.
signal.line: a number, the width of the lines cross the circle
cir.chr: logical, a boundary represents chromosome, the default is TRUE.
cir.chr.h: a number, the width for the boundary, if cir.chr=FALSE, then this parameter will be useless.
chr.den.col: a character or vector or NULL, the colour for the SNP density. If the length of parameter 'chr.den.col' is bigger than 1, SNP density that counts
the number of SNP within given size('bin.size') will be plotted around the circle. If chr.den.col=NULL, then the default colours are the same with the parameter "col" for circle.
cir.legend: logical, whether to add the legend of each circle.
cir.legend.cex: a number, the size of the number of legend.
cir.legend.col: a character, the color of the axis of legend.
LOG10: logical, whether to change the p-value into log10(p-value).
box: logical, this function draws a box around the current Manhattan plot.
conf.int.col: a character, the color of the confidence interval on QQ-plot.
file.output: a logical, users can choose whether to output the plot results.
file: a character, users can choose the different output formats of plot, so for, "jpg", "pdf", "tiff" can be selected by users.
dpi: a number, the picture element for .jpg and .tiff files. The default is 300.
memo: add a character to the output file name.
verbose: whether print the reminder.
推荐阅读
-
理解工作流:自动化业务流程管理与Activiti实践" **简述** 工作流(Workflow)是一种利用电脑技术自动化管理业务流程的方式,让不同参与者按既定路径执行任务,确保文档、信息或任务在预设规则下顺利传递,最终达成期望的业务目标。 **核心概念** - **工作流自动化**: 计算机驱动业务流程处理与执行,如在参与者间自动传递文档和任务。 - **目标与应用**: 管理工作流程确保按时、由合适的人执行,同时允许人工介入以增强灵活性。 - **工作流框架示例**: Activiti、JBPM、OSWorkflow 和 Workflow,它们背后通常依赖数据库支持。 - **关键组件**: ProcessEngine 在 Activiti 中扮演核心角色,负责流程实例创建、数据管理和流程监控。 **相关领域** - **业务流程管理 (BPM)**: 一种系统性方法论,聚焦于构建并优化端到端卓越业务流程以提升企业业绩,在EMBA、MBA等商业课程中得到关注。 - **业务流程建模与标记语言 (BPMN)**: 用于绘制业务流程图的工具,探讨其在不同场景下的应用精确度、标准化价值以及未来发展愿景。 **辅助术语** - 流对象 (Flow Objects): BPMN 中用于描述流程中活动、决策、序列和其他元素的具体实现单元。
-
关于使用多维组织学通路分析 R 软件包 ActivePathways 和 Cytoscape 绘制网络图的实用教程
-
用 R 语言绘制 Vonoroi 图的完整代码
-
R 语言绘制生产步骤的密度图(密度图
-
用于绘制曼哈顿图的 R 语言 CMplot 软件包
-
sem在R语言中的应用,用于结构方程建模和路径图可视化
-
包婷婷 (201550484)作业一 统计软件简介与数据操作-SPSS(Statistical Product and Service Solutions),"统计产品与服务解决方案"软件。最初软件全称为"(SolutionsStatistical Package for the Social Sciences),但是随着SPSS产品服务领域的扩大和服务深度的增加,SPSS公司已于2000年正式将英文全称更改为"统计产品与服务解决方案",标志着SPSS的战略方向正在做出重大调整。为IBM公司推出的一系列用于统计学分析运算、数据挖掘、预测分析和决策支持任务的软件产品及相关服务的总称SPSS,有Windows和Mac OS X等版本。 1984年SPSS总部首先推出了世界上第一个统计分析软件微机版本SPSS/PC+,开创了SPSS微机系列产品的开发方向,极大地扩充了它的应用范围,并使其能很快地应用于自然科学、技术科学、社会科学的各个领域。世界上许多有影响的报刊杂志纷纷就SPSS的自动统计绘图、数据的深入分析、使用方便、功能齐全等方面给予了高度的评价。 R统计软件介绍 R是一套完整的数据处理、计算和制图软件系统。其功能包括:数据存储和处理系统;数组运算工具(其向量、矩阵运算方面功能尤其强大);完整连贯的统计分析工具;优秀的统计制图功能;简便而强大的编程语言:可操纵数据的输入和输出,可实现分支、循环,用户可自定义功能。 与其说R是一种统计软件,还不如说R是一种数学计算的环境,因为R并不是仅仅提供若干统计程序、使用者只需指定数据库和若干参数便可进行一个统计分析。R的思想是:它可以提供一些集成的统计工具,但更大量的是它提供各种数学计算、统计计算的函数,从而使使用者能灵活机动的进行数据分析,甚至创造出符合需要的新的统计计算方法。 该语言的语法表面上类似 C,但在语义上是函数设计语言(functional programming language)的变种并且和Lisp 以及 APL有很强的兼容性。特别的是,它允许在"语言上计算"(computing on the language)。这使得它可以把表达式作为函数的输入参数,而这种做法对统计模拟和绘图非常有用。 R是一个免费的*软件,它有UNIX、LINUX、MacOS和WINDOWS版本,都是可以免费下载和使用的。在R主页那儿可以下载到R的安装程序、各种外挂程序和文档。在R的安装程序中只包含了8个基础模块,其他外在模块可以通过CRAN获得。 二、R语言 R是用于统计分析、绘图的语言和操作环境。R是属于GNU系统的一个*、免费、源代码开放的软件,它是一个用于统计计算和统计制图的优秀工具。 R作为一种统计分析软件,是集统计分析与图形显示于一体的。它可以运行于UNIX,Windows和Macintosh的操作系统上,而且嵌入了一个非常方便实用的帮助系统,相比于其他统计分析软件,R还有以下特点: 1.R是*软件。这意味着它是完全免费,开放源代码的。可以在它的网站及其镜像中下载任何有关的安装程序、源代码、程序包及其源代码、文档资料。标准的安装文件身自身就带有许多模块和内嵌统计函数,安装好后可以直接实现许多常用的统计功能。[2] 2.R是一种可编程的语言。作为一个开放的统计编程环境,语法通俗易懂,很容易学会和掌握语言的语法。而且学会之后,我们可以编制自己的函数来扩展现有的语言。这也就是为什么它的更新速度比一般统计软件,如,SPSS,SAS等快得多。大多数最新的统计方法和技术都可以在R中直接得到。[2] 3. 所有R的函数和数据集是保存在程序包里面的。只有当一个包被载入时,它的内容才可以被访问。一些常用、基本的程序包已经被收入了标准安装文件中,随着新的统计分析方法的出现,标准安装文件中所包含的程序包也随着版本的更新而不断变化。在另外版安装文件中,已经包含的程序包有:base一R的基础模块、mle一极大似然估计模块、ts一时间序列分析模块、mva一多元统计分析模块、survival一生存分析模块等等.[2] 4.R具有很强的互动性。除了图形输出是在另外的窗口处,它的输入输出窗口都是在同一个窗口进行的,输入语法中如果出现错误会马上在窗口口中得到提示,对以前输入过的命令有记忆功能,可以随时再现、编辑修改以满足用户的需要。输出的图形可以直接保存为JPG,BMP,PNG等图片格式,还可以直接保存为PDF文件。另外,和其他编程语言和数据库之间有很好的接口。[2] 5.如果加入R的帮助邮件列表一,每天都可能会收到几十份关于R的邮件资讯。可以和全球一流的统计计算方面的专家讨论各种问题,可以说是全世界最大、最前沿的统计学家思维的聚集地.[2] R是基于S语言的一个GNU项目,所以也可以当作S语言的一种实现,通常用S语言编写的代码都可以不作修改的在R环境下运行。 R的语法是来自Scheme。R的使用与S-PLUS有很多类似之处,这两种语言有一定的兼容性。S-PLUS的使用手册,只要稍加修改就可作为R的使用手册。所以有人说:R,是S-PLUS的一个“克隆”。 但是请不要忘了:R是免费的(R is free)。R语言源代码托管在github,具体地址可以看参考资料。[3] 。 R语言的下载可以通过CRAN的镜像来查找。 R语言有域名为.cn的下载地址,有六个,其中两个由Datagurn,由 中国科学技术大学提供的。R语言Windows版,其中由两个下载地点是Datagurn和 USTC提供的。 三、stata Stata 是一套提供其使用者数据分析、数据管理以及绘制专业图表的完整及整合性统计软件。它提供许许多多功能,包含线性混合模型、均衡重复反复及多项式普罗比模式。用Stata绘制的统计图形相当精美。 新版本的STATA采用最具亲和力的窗口接口,使用者自行建立程序时,软件能提供具有直接命令式的语法。Stata提供完整的使用手册,包含统计样本建立、解释、模型与语法、文献等超过一万余页的出版品。 除此之外,Stata软件可以透过网络实时更新每天的最新功能,更可以得知世界各地的使用者对于STATA公司提出的问题与解决之道。使用者也可以透过Stata. Journal获得许许多多的相关讯息以及书籍介绍等。另外一个获取庞大资源的管道就是Statalist,它是一个独立的listserver,每月交替提供使用者超过1000个讯息以及50个程序。 四、PYTHON
-
r 语言绘制动态统计数据:绘制世界各国人均 GDP、出生时预期寿命和人口气泡图的动态 gif 动画 | 带代码的数据
-
R 语言 ggplot2 绘制云雨图的简单小示例
-
使用 sjPlot 软件包,R 可以优雅地绘制回归模型的交互效应图