Created
May 10, 2024 16:24
-
-
Save Zepeng-Mu/c0e7a7e55ea3d05b8a7cd44e5ad57383 to your computer and use it in GitHub Desktop.
Plot COLOC results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggColocManhattanSingle <- function( | |
summ.1, chr = "CHR", bp = "BP", p = "P", snp = "SNP", | |
summ.1.name = expression(paste("", -log[10](P))), | |
logp = TRUE, size = 2, lead.snp = NULL, r2 = NULL, ... | |
) { | |
if (!is.null(summ.1[[snp]])) { | |
d1 <- data.frame(CHR = summ.1[[chr]], BP = summ.1[[bp]], P = summ.1[[p]], SNP = summ.1[[snp]]) | |
} else { | |
d1 <- data.frame(CHR = summ.1[[chr]], BP = summ.1[[bp]], P = summ.1[[p]]) | |
} | |
# Calculate -log(P) for summ.1 and summ.2 | |
if (logp) { | |
d1$logp <- -log10(d1$P) | |
} else { | |
d1$logp <- d1$P | |
} | |
# Map SNP r2 to discrete colors | |
# This is inspired by locuscomparer package | |
if (is.null(r2)) { | |
snp.col <- rep("grey", nrow(d1)) | |
} else { | |
snp.col <- as.character(cut(r2, breaks = c(0, 0.2, 0.4, 0.6, 0.8, 1), | |
labels = c('blue','lightblue','darkgreen','orange','red'), | |
include.lowest = T)) | |
} | |
g1 <- ggplot() + | |
cowplot::theme_cowplot(font_size = 4, line_size = 0.2, font_family = "Helvetica") + | |
ggrastr::rasterise(geom_point(data = d1, mapping = aes(x = BP / 1e6, y = logp), | |
col = snp.col, size = 0.5), dpi = 960, scale = 0.5) + | |
ggrastr::rasterise(geom_point(data = d1 %>% filter(BP %in% lead.snp), | |
mapping = aes(x = BP / 1e6, y = logp), | |
col = "purple", shape = 18, size = 1), dpi = 960) + | |
scale_y_continuous(limits = c(0, max(d1$logp) * 1.05), expand = c(0, 0)) + | |
scale_x_continuous(expand = c(0, 0)) + | |
xlab("") + | |
ylab(summ.1.name) + | |
theme(plot.margin = unit(c(0, 0, 0, 0), "in"), axis.title.y = ggtext::element_markdown()) | |
return(g1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function plots a single Manhattan plot. Two plots can be combined to visualize colocalization results.