这篇文章将为大家详细讲解有关如何进行R语言ggplot2包画曼哈顿图的简单分析,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
曼哈顿图是GWAS数据分析中经常会用到的一个图,R语言里有专门的包和函数直接生成曼哈顿图。但是如果有数据的话我们自己也可以用ggplot2来做。
做曼哈顿图的数据通常是以下这种格式
image.png曼哈顿图可以理解成一个x对应多个y的散点图,ggplot2里做这种图的函数是geom_jitter()
今天用到的数据集是来自于rMVP
这个包中的pig60K
数据集
首先是获得这个数据集library(rMVP)
data('pig60K')
使用ggplot2画图library(ggplot2)
ggplot(pig60K,aes(x=Chromosome,y=trait1))+
geom_jitter()
image.png 按不同的染色体填充颜色ggplot(pig60K,aes(x=Chromosome,y=trait1))+
geom_jitter(aes(color=Chromosome))
image.png 右侧的图例可以不要,把它去掉ggplot(pig60K,aes(x=Chromosome,y=trait1))+
geom_jitter(aes(color=Chromosome))+
theme(legend.position = "none")
image.png 从图上可以看到Y染色体对应的只有一个点,可以在原始数据中把Y对应的数据去掉,用到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")
image.png 这个时候还有一个问题是X轴不是按照1,2,3这样依次排下来的,我们可以通过更改因子水平来给X轴重新排序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")
image.png 曼哈顿图通常是对特征的p值取-log10ggplot(df,aes(x=Chromosome,y=-log10(trait1)))+
geom_jitter(aes(color=Chromosome))+
theme(legend.position = "none")
image.png 最后是一些简单的美化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包画曼哈顿图的简单分析就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。