如何进行R语言ggplot2包画曼哈顿图的简单分析
这篇文章将为大家详细讲解有关如何进行R语言ggplot2包画曼哈顿图的简单分析,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
曼哈顿图是GWAS数据分析中经常会用到的一个图,R语言里有专门的包和函数直接生成曼哈顿图。但是如果有数据的话我们自己也可以用ggplot2来做。
做曼哈顿图的数据通常是以下这种格式
第一列是SNP对应的一个名字 第二列是染色体编号 第三列是SNP在染色体的位置 第四列是特征对应的一个P值 如果有多个特征依次往后排就可以了
曼哈顿图可以理解成一个x对应多个y的散点图,ggplot2里做这种图的函数是geom_jitter()
今天用到的数据集是来自于
rMVP
这个包中的pig60K
数据集
library(rMVP)
data('pig60K')
library(ggplot2)
ggplot(pig60K,aes(x=Chromosome,y=trait1))+
geom_jitter()
ggplot(pig60K,aes(x=Chromosome,y=trait1))+
geom_jitter(aes(color=Chromosome))
ggplot(pig60K,aes(x=Chromosome,y=trait1))+
geom_jitter(aes(color=Chromosome))+
theme(legend.position = "none")
dplyr
这个包中的filter()
函数library(dplyr)
df<-filter(pig60K,Chromosome!="Y")
ggplot(df,aes(x=Chromosome,y=trait1))+
geom_jitter(aes(color=Chromosome))+
theme(legend.position = "none")
df$Chromosome<-factor(df$Chromosome,
levels = c(1:18,"X"))
ggplot(df,aes(x=Chromosome,y=trait1))+
geom_jitter(aes(color=Chromosome))+
theme(legend.position = "none")
ggplot(df,aes(x=Chromosome,y=-log10(trait1)))+
geom_jitter(aes(color=Chromosome))+
theme(legend.position = "none")
ggplot(df,aes(x=Chromosome,y=-log10(trait1)))+
geom_jitter(aes(color=Chromosome))+
theme_minimal()+
theme(legend.position = "none",
axis.text.x = element_text(angle=60,hjust=1))+
scale_y_continuous(expand = c(0,0),
limits = c(0,10))+
scale_x_discrete(labels=paste0("Chr",c(1:18,"X")))+
labs(x=NULL,y="-log10(Pvalue)")+
geom_hline(yintercept = 6.25,lty="dashed")
关于如何进行R语言ggplot2包画曼哈顿图的简单分析就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。