-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Colour SNP points according to annotation2 rather than chromosome? #13
Comments
Thanks for your interest in this package. Several people have asked for this feature. I will try to implement it in a function. for the time being, here is some code that should get you started: library(manhattanly)
library(magrittr)
DT <- subset(HapMap, CHR %in% 1:3)
DT$region <- sample(c("Africa", "MiddleEast"), size = nrow(DT), replace = TRUE)
x <- manhattanr(DT, snp = "SNP", gene = "GENE", annotation1 = "region")
d <- x$data
pName <- x$pName
snpName <- x$snpName
geneName <- x$geneName
annotation1Name <- x$annotation1Name
annotation2Name <- x$annotation2Name
labs <- x$labs
xlabel <- x$xlabel
ticks <- x$ticks
nchr <- x$nchr
xmax = ceiling(max(d$pos) * 1.03)
xmin = floor(max(d$pos) * -0.03)
p <- plotly::plot_ly()
p %<>% plotly::layout(p, title = "Title",
xaxis = list(title = "Chromosome",
showgrid = FALSE, range = c(xmin, xmax), autotick = FALSE,
tickmode = "array", tickvals = ticks, ticktext = labs,
ticks = "outside"), yaxis = list(title = "-log10(p)"))
icol <- 1
for (i in unique(d$index)) {
tmp <- d[d$index == unique(d$index)[i], ]
TEXT <- paste(if (!is.na(snpName))
paste0(snpName, ": ", tmp[[snpName]]), if (!is.na(geneName))
paste0(geneName, ": ", tmp[[geneName]]), if (!is.na(annotation1Name))
paste0(annotation1Name, ": ", tmp[[annotation1Name]]),
if (!is.na(annotation2Name))
paste0(annotation2Name, ": ", tmp[[annotation2Name]]),
sep = "<br>")
chromo <- unique(tmp[which(tmp$index == i), "CHR"])
p %<>% add_markers(x = tmp$pos, y = tmp$logp, color = tmp$region,
showlegend = F, text = TEXT, name = paste0("chr", chromo))
icol = icol + 1
}
p See the resulting plot here: |
Thanks so much Sahir, I've managed to integrate that into the function code that I have and it's working beautifully! |
Hi Sahir, Thanks for creating such a useful package. On a similar note, is it possible to Thanks again for the contribution! |
Hi Sahir, |
Hi Sahir,
First of all thanks for creating such a fantastic package! I've been trying and failing to edit some of the code in the package for a while now in order to recolour the SNP points according to another variable rather than chromosome number in the manhattan plots, and I was wondering whether you could help? I want to colour the SNPs according to geographical region (of which I have two) as I have multiple populations plotted on the same manhattan plot. When transforming my dataset into the manhattanr class I saved this region variable as the annotation2 so each SNP has either the region "Africa" or "MiddleEast" in the annotation2 column. So is there a way I can colour points according to annotation2 rather than chromosome?
Many Thanks,
Sophie
The text was updated successfully, but these errors were encountered: