qq plot 是为了检验实际分布与假设分布是否相同。
    我的数据来自于plink处理后生成的p值,所以不同的分布根据实际情况修改。
    下面函数来自于 qqman 包,可定制性太差,就改下用ggplot2画。

    1. qq = function(pvector, ...) {
    2. # Check for sensible input
    3. if (!is.numeric(pvector)) stop("Input must be numeric.")
    4. # limit to not missing, not nan, not null, not infinite, between 0 and 1
    5. pvector <- pvector[!is.na(pvector) & !is.nan(pvector) & !is.null(pvector) & is.finite(pvector) & pvector<1 & pvector>0]
    6. # Observed and expected
    7. o = -log10(sort(pvector,decreasing=FALSE))
    8. e = -log10( ppoints(length(pvector) ))
    9. # # The old way
    10. # plot(e, o, pch=20,
    11. # xlab=expression(Expected~~-log[10](italic(p))),
    12. # ylab=expression(Observed~~-log[10](italic(p))),
    13. # ...)
    14. # The new way to initialize the plot.
    15. ## See http://stackoverflow.com/q/23922130/654296
    16. ## First, define your default arguments
    17. def_args <- list(pch=20, xlim=c(0, max(e)), ylim=c(0, max(o)),
    18. xlab=expression(Expected~~-log[10](italic(p))),
    19. ylab=expression(Observed~~-log[10](italic(p)))
    20. )
    21. ## Next, get a list of ... arguments
    22. #dotargs <- as.list(match.call())[-1L]
    23. dotargs <- list(...)
    24. ## And call the plot function passing NA, your ... arguments, and the default
    25. ## arguments that were not defined in the ... arguments.
    26. tryCatch(do.call("plot", c(list(x=e, y=o), def_args[!names(def_args) %in% names(dotargs)], dotargs)), warn=stop)
    27. # Add diagonal
    28. abline(0,1,col="red")
    29. }

    使用 ggplot2 作图

    1. qq_dat <- data.frame(obs=-log10(sort(pd_dat$P,decreasing=FALSE)),
    2. exp=-log10( ppoints(length(pd_dat$P))))
    3. pd_qq <- ggplot(data=qq_dat,aes(exp,obs))+
    4. geom_point(alpha=0.7,color="#7F7F7FFF")+
    5. geom_abline(color="#D62728FF")+
    6. xlab("Expected -log10(P-value)")+
    7. ylab("Observed -log10(P-value)")+
    8. scale_x_continuous(limits = c(0,7))+
    9. scale_y_continuous(limits = c(0,7))+
    10. theme(
    11. axis.title = element_text(size=12,face="bold"),
    12. axis.text = element_text(face="bold",size=8,color = "black"),
    13. #axis.line = element_line(size=0.8,color="black"),
    14. axis.ticks= element_line(size=0.8,colour = "black"),
    15. panel.grid =element_blank(),
    16. panel.border = element_rect(fill=NA,size = 0.8),
    17. panel.background = element_blank())

    plot_zoom_png.png