之前使用popLDdeacy這個(gè)軟件自動(dòng)生成的圖片不是特別好看弱睦,重新繪制了一下莽使,記錄一下。
popLDdeacy 生成的圖片
在使用LDdecay計(jì)算LD 衰減的時(shí)候,會(huì)返回OUT.bin.gz尸疆,前兩列為繪圖所需的數(shù)據(jù)莲镣。
OUT.bin.gz 部分?jǐn)?shù)據(jù)
- 使用系統(tǒng)函數(shù)繪制
# 我選用的LD衰減距離是r2 一半的時(shí)候的距離
rm(list = ls()) # 清除工作環(huán)境中的變量
setwd("M:\\LD衰減圖")
LD <- read.table(gzfile("./OUT.bin.gz"),header = T,sep = "\t") # 讀入數(shù)據(jù)
plot(LD$Dist/1000,LD$Mean_r.2,type = "l",col="blue",main="LD decay",xlab = "Distance(Kb)",ylab = expression(r^{2}),cex=3,panel.first = grid(),panel.last = grid())
# Dist_avage <- round((max(LD$Dist)-min(LD$Dist))/2)
segments(0,0.3368,67,0.3368,lty=4,col="red") # 加上虛線
segments(67,0,67,0.3368,lty=4,col="red")
# abline(h=0.3368,v=67,lty=3,col="lightgray")
text(67,0.3368,"(67,0.3368881)",pos = 4,font = 4,cex = 0.8) # 加上坐標(biāo)點(diǎn)
LD衰減圖
- 使用 ggplot2 繪制
rm (list = ls() )
library(ggplot2) # 調(diào)用 ggplot2
setwd("M:\\LD衰減圖")
LD <- read.table(gzfile("./OUT.bin.gz"),header = T,sep = "\t")
p <- ggplot(data=LD,mapping = aes(x=Dist/1000,y=Mean_r.2))+
geom_line(color="blue")+
geom_segment(aes(x = 67,y=0.3368881,xend=0,yend=0.3366881),data = NULL,colour="red",lty=2,lwd=0.8,lineend = "butt")+
geom_segment(aes(x = 67,y=0,xend=67,yend=0.33668881),data = NULL,colour="red",lty=2,lwd=0.8)+
geom_text(aes(x=67,y=0.3368881),label=c("(67,0.3368881)"),hjust=0,nudge_x = 0.002,size=3)+
labs(y=expression(r^{2}),title = "LD decay")+
xlab("Distance")+
scale_x_continuous(c(0:300),breaks = c(seq(0,300,50)))+
theme_bw()
p <- p+theme(plot.title = element_text(hjust = 0.5)) # 使主標(biāo)題居中
p
LD衰減圖