一般使用 CMplot 绘制SNP密度图:
包链接:https://github.com/YinLiLin/R-CMplot
要绘制 SNP 密度图,仅仅需要三列即可:
a. 第一列是 SNP 名称
b. 第二列是染色体
c. 第三列是 SNP 的位置
d. 第四列开始为不同性状的P值
1. 示例数据:
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
2. 安装 CMplot 包
install.packages("CMplot")
library("CMplot")
3. 作图代码
首先读取数据
pig60k <- read.table("data.txt",header=T)
3.1 示例1 -- 密度条形图
# 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.
data(pig60K)
CMplot(
pig60K, plot.type="d", bin.size=1e6, col=c("darkgreen", "yellow", "red"),
file="jpg", memo="Fig1", dpi=300, file.output=TRUE, verbose=TRUE
)
3.2 示例2 -- 环状图
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="Fig2", dpi=300, file.output=TRUE, verbose=TRUE
)
3.3 示例3 -- 多层圈图
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.
3.4 示例4 -- 曼哈顿图
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.
3.5 示例5 -- 曼哈顿 + 条形图
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.
3.6 示例6 -- 分染色体曼哈顿图
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
)
3.7 示例7 -- 单性状 QQ 图
CMplot(
pig60K,plot.type="q",conf.int.col=NULL,box=TRUE,file="jpg",memo="",dpi=300,
file.output=TRUE,verbose=TRUE
)
3.8 示例8 -- 多性状 QQ 图
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
)
4. CMplot 的参数及解释:
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.
感觉作者好棒!