Skip to content

Instantly share code, notes, and snippets.

@liangyy
Last active October 17, 2020 17:12
Show Gist options
  • Save liangyy/4c647634fe00b3f042ebd1599dda65c7 to your computer and use it in GitHub Desktop.
Save liangyy/4c647634fe00b3f042ebd1599dda65c7 to your computer and use it in GitHub Desktop.
qqplot_by_group <- function(pval, group, ...) {
n <- length(pval)
pexp <- rank(pval) / n
df <- data.frame(p.val = pval, grp = group) %>% group_by(grp) %>% mutate(p.exp = rank(p.val) / (n() + 1)) %>% ungroup()
p <- ggplot(df) +
geom_point(aes(x = -log10(p.exp), y = -log10(p.val), color = grp), ...) +
geom_hline(yintercept = -log10(0.05 / n)) +
geom_abline(slope = 1, intercept = 0, linetype = 2)
return(p)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment