绘图技巧遗传学

绘制LD衰减图

2021-03-18  本文已影响0人  123678

之前使用popLDdeacy这个软件自动生成的图片不是特别好看,重新绘制了一下,记录一下。

popLDdeacy 生成的图片

在使用LDdecay计算LD 衰减的时候,会返回OUT.bin.gz,前两列为绘图所需的数据。

OUT.bin.gz 部分数据
  1. 使用系统函数绘制
# 我选用的LD衰减距离是r2 一半的时候的距离
rm(list = ls())  # 清除工作环境中的变量
setwd("M:\\LD衰减图") 
LD <- read.table(gzfile("./OUT.bin.gz"),header = T,sep = "\t") # 读入数据
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) # 加上坐标点 
LD衰减图
  1. 使用 ggplot2 绘制
rm (list = ls() )
library(ggplot2) # 调用 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)) # 使主标题居中
p
LD衰减图
上一篇下一篇

猜你喜欢

热点阅读