# library(data.table)
# library(ggplot2)
# library(scales)
fortify.manhattan <- function(data, x, y, group) {
map_chro <- c(seq(22), "X", "Y", "X", "Y")
names(map_chro) <- c(seq(24), "X", "Y")
`:=` <- data.table::`:=`
out <- data.table::as.data.table(data)
data.table::setnames(out, c(x, y, group), c("x_pos", "y_pval", "x_chr"))
out[, x_chr := as.character(x_chr)]
out[, x_chr := map_chro[gsub("^chr", "", x_chr, ignore.case = TRUE)]]
out[, x_chr := factor(x_chr, levels = intersect(c(seq(22), "X", "Y"), x_chr))]
out[, x_pos := as.double(x_pos)]
out[order(x_chr, x_pos)]
out[, x_pos := scales::rescale(x = x_pos, to = c(-0.4, 0.4)), by = "x_chr"]
out[, x_pos := x_pos + as.integer(x_chr)]
data.table::setnames(out, c("x_pos", "y_pval", "x_chr"), c("x", "y", "group"))
out[]
}
StatManhattan <- ggplot2::ggproto("StatManhattan", ggplot2::Stat,
required_aes = c("x", "y", "group"),
setup_data = function(data, params) {
fortify.manhattan(data, "x", "y", "group")
},
compute_layer = function(data, scales, params) {
data
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.