# Load the librarylibrary(qqman)#> #> For example usage please run: vignette('qqman')#> #> Citation appreciated but not required:#> Turner, (2018). qqman: an R package for visualizing GWAS results using Q-Q and manhattan plots. Journal of Open Source Software, 3(25), 731, https://doi.org/10.21105/joss.00731.#> gwasResults%>%head()#> SNP CHR BP P#> 1 rs1 1 1 0.9148060#> 2 rs2 1 2 0.9370754#> 3 rs3 1 3 0.2861395#> 4 rs4 1 4 0.8304476#> 5 rs5 1 5 0.6417455#> 6 rs6 1 6 0.5190959# Make the Manhattan plot on the gwasResults datasetmanhattan(gwasResults, chr="CHR", bp="BP", snp="SNP", p="P")
don<-gwasResults%>%# Compute chromosome sizegroup_by(CHR)%>%summarise(chr_len=max(BP))%>%# Calculate cumulative position of each chromosomemutate(tot=cumsum(chr_len)-chr_len)%>%select(-chr_len)%>%# Add this info to the initial datasetleft_join(gwasResults, ., by=c("CHR"="CHR"))%>%# Add a cumulative position of each SNParrange(CHR, BP)%>%mutate( BPcum=BP+tot)axisdf=don%>%group_by(CHR)%>%summarize(center=(max(BPcum)+min(BPcum))/2)
Code
ggplot(don, aes(x=BPcum, y=-log10(P)))+# Show all pointsgeom_point(aes(color=as.factor(CHR)), alpha=0.8, size=1.3)+scale_color_manual(values =rep(c("grey", "skyblue"), 22))+# custom X axis:scale_x_continuous( label =axisdf$CHR, breaks=axisdf$center)+scale_y_continuous(expand =c(0, 0))+# remove space between plot area and x axis# Custom the theme:theme_bw()+theme( legend.position="none", panel.border =element_blank(), panel.grid.major.x =element_blank(), panel.grid.minor.x =element_blank())
Code
# List of SNPs to highlight are in the snpsOfInterest object# We will use ggrepel for the annotationlibrary(ggrepel)# Prepare the datasetdon<-gwasResults%>%# Compute chromosome sizegroup_by(CHR)%>%summarise(chr_len=max(BP))%>%# Calculate cumulative position of each chromosomemutate(tot=cumsum(chr_len)-chr_len)%>%select(-chr_len)%>%# Add this info to the initial datasetleft_join(gwasResults, ., by=c("CHR"="CHR"))%>%# Add a cumulative position of each SNParrange(CHR, BP)%>%mutate( BPcum=BP+tot)%>%# Add highlight and annotation informationmutate( is_highlight=ifelse(SNP%in%snpsOfInterest, "yes", "no"))%>%mutate( is_annotate=ifelse(-log10(P)>4, "yes", "no"))# Prepare X axisaxisdf<-don%>%group_by(CHR)%>%summarize(center=(max(BPcum)+min(BPcum))/2)# Make the plotggplot(don, aes(x=BPcum, y=-log10(P)))+# Show all pointsgeom_point(aes(color=as.factor(CHR)), alpha=0.8, size=1.3)+scale_color_manual(values =rep(c("grey", "skyblue"), 22))+# custom X axis:scale_x_continuous( label =axisdf$CHR, breaks=axisdf$center)+scale_y_continuous(expand =c(0, 0))+# remove space between plot area and x axis# Add highlighted pointsgeom_point(data=subset(don, is_highlight=="yes"), color="orange", size=2)+# Add label using ggrepel to avoid overlappinggeom_label_repel( data=subset(don, is_annotate=="yes"), aes(label=SNP), size=2)+# Custom the theme:theme_bw()+theme( legend.position="none", panel.border =element_blank(), panel.grid.major.x =element_blank(), panel.grid.minor.x =element_blank())#> Warning: ggrepel: 31 unlabeled data points (too many overlaps). Consider#> increasing max.overlaps
library(plotly)# Prepare the datasetdon<-gwasResults%>%# Compute chromosome sizegroup_by(CHR)%>%summarise(chr_len=max(BP))%>%# Calculate cumulative position of each chromosomemutate(tot=cumsum(chr_len)-chr_len)%>%select(-chr_len)%>%# Add this info to the initial datasetleft_join(gwasResults, ., by=c("CHR"="CHR"))%>%# Add a cumulative position of each SNParrange(CHR, BP)%>%mutate( BPcum=BP+tot)%>%# Add highlight and annotation informationmutate( is_highlight=ifelse(SNP%in%snpsOfInterest, "yes", "no"))%>%# Filter SNP to make the plot lighterfilter(-log10(P)>0.5)# Prepare X axisaxisdf<-don%>%group_by(CHR)%>%summarize(center=(max(BPcum)+min(BPcum))/2)# Prepare text description for each SNP:don$text<-paste("SNP: ", don$SNP, "\nPosition: ", don$BP, "\nChromosome: ", don$CHR, "\nLOD score:", -log10(don$P)%>%round(2), "\nWhat else do you wanna know", sep="")# Make the plotp<-ggplot(don, aes(x=BPcum, y=-log10(P), text=text))+# Show all pointsgeom_point(aes(color=as.factor(CHR)), alpha=0.8, size=1.3)+scale_color_manual(values =rep(c("grey", "skyblue"), 22))+# custom X axis:scale_x_continuous( label =axisdf$CHR, breaks=axisdf$center)+scale_y_continuous(expand =c(0, 0))+# remove space between plot area and x axisylim(0,9)+# Add highlighted pointsgeom_point(data=subset(don, is_highlight=="yes"), color="orange", size=2)+# Custom the theme:theme_bw()+theme( legend.position="none", panel.border =element_blank(), panel.grid.major.x =element_blank(), panel.grid.minor.x =element_blank())#> Scale for y is already present.#> Adding another scale for y, which will replace the existing scale.p=ggplotly(p, tooltip="text")p
1.4 CMplot 的环形版本
Code
library("CMplot")#> Much appreciate for using CMplot.#> Full description, Bug report, Suggestion and the latest codes:#> https://github.com/YinLiLin/CMplot