Ks密度曲线分布图绘图
2019-11-06 本文已影响0人
Davey1220
Ka(dN)
代表每非同义位点的碱基替代数,而Ks(dS)
则代表每同义位点的碱基替代数,Ka/Ks
的比值常用于判断某个蛋白编码基因是否受到选择压力的作用。一般认为,当Ka/Ks>1
时,则认为有正选择效应
。当Ka/Ks=1
时,则认为存在中性选择
。当Ka/Ks<1
时,则认为有纯化选择
的作用。常用的选择压力Ka/Ks的计算工具有PAML包中的yn00
程序,或KaKs_calculator
等软件。Ks密度曲线分布图常用于判断某一物种在长期的进化过程中是否发生了基因组加倍事件,根据密度曲线对应峰值的Ks值以及该物种核苷酸碱基的替代速率,可以大致计算出该物种发生加倍的进化时间。
加载所需R包
rm(list=ls())
library(ggplot2)
library(reshape2)
设置工作路径并加载数据
setwd("/Users/Davey/Desktop")
data <- read.table("test_ks.txt",header = T,sep="\t")
data <- melt(data,variable.name="Species",value.name = "Ks")
#去除缺失的行
data = na.omit(data)
head(data)
## Species Ks
## 1 SpeciesA_SpeciesB 0.0915
## 2 SpeciesA_SpeciesB 0.2535
## 3 SpeciesA_SpeciesB 0.0386
## 4 SpeciesA_SpeciesB 0.1385
## 5 SpeciesA_SpeciesB 0.1125
## 6 SpeciesA_SpeciesB 0.1960
使用ggplot2绘图
p1 <- ggplot(data,aes(Ks,fill=Species,color=Species,alpha=0.8)) +`
geom_density() + xlim(0,1) + theme_classic() + geom_rug() +
guides(alpha=FALSE) +
theme(axis.title = element_text(size=16),axis.text=element_text(size=16),legend.position = "top")
p1
#ggsave("Ks_plot.png",p1)
ggsave("Ks_plot.pdf",p1)
image
p2 <- ggplot(data,aes(Ks,color=Species)) +
geom_line(stat="density") + xlim(0,1) + theme_bw() +
theme(axis.title = element_text(size=16),axis.text=element_text(size=16))
p2
image
p3 <- ggplot(data,aes(Ks,fill=Species,color=Species)) +
geom_histogram(bins=100) + geom_rug() +
xlim(0,1) + theme_bw() +
theme(axis.title = element_text(size=16),axis.text=element_text(size=16))
p3
image
p4 <- ggplot(data,aes(Ks,..density..,fill=Species)) +
geom_histogram(bins=100) + geom_line(stat="density") +
xlim(0,1) + theme_bw() + facet_grid(Species~.) +
theme(axis.title = element_text(size=16),axis.text=element_text(size=16))
p4
image
sessionInfo()
## R version 3.5.1 (2018-07-02)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: OS X El Capitan 10.11.3
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
##
## locale:
## [1] zh_CN.UTF-8/zh_CN.UTF-8/zh_CN.UTF-8/C/zh_CN.UTF-8/zh_CN.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggpubr_0.1.7.999 magrittr_1.5 reshape2_1.4.3 ggplot2_3.0.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.18 rstudioapi_0.7 bindr_0.1.1 knitr_1.20
## [5] tidyselect_0.2.4 munsell_0.5.0 colorspace_1.3-2 R6_2.2.2
## [9] rlang_0.2.2 stringr_1.3.1 plyr_1.8.4 dplyr_0.7.6
## [13] tools_3.5.1 grid_3.5.1 gtable_0.2.0 withr_2.1.2
## [17] htmltools_0.3.6 assertthat_0.2.0 yaml_2.2.0 lazyeval_0.2.1
## [21] rprojroot_1.3-2 digest_0.6.16 tibble_1.4.2 crayon_1.3.4
## [25] bindrcpp_0.2.2 purrr_0.2.5 glue_1.3.0 evaluate_0.11
## [29] rmarkdown_1.10 labeling_0.3 stringi_1.2.4 compiler_3.5.1
## [33] pillar_1.3.0 scales_1.0.0 backports_1.1.2 pkgconfig_2.0.2