# library(data.table)
# library(ggplot2)
# library(ggtext)
# devtools::source_gist("d7cbc59a7fcbb6d231f432801ec7aa19") # pval_trans)
draw_volcano <- function(
data, x, y,
label_x = "Fold-Change (log<sub>2</sub>)",
label_y = "P-value",
alpha = 0.05
) {
data <- data.table::as.data.table(data)#[, .SD, .SDcols = c(x, y)]
data.table::setnames(data, y, "pvalue", skip_absent = TRUE)
ggplot2::ggplot(data) +
ggplot2::aes(x = .data[[x]], y = .data[["pvalue"]], colour = abs(.data[[x]])) +
ggplot2::geom_vline(xintercept = 0, linetype = 2) +
ggplot2::geom_point(size = 0.60) +
ggplot2::scale_colour_viridis_c(trans = "sqrt", limits = c(0, NA)) +
ggplot2::labs(x = label_x, y = label_y) +
ggplot2::theme(legend.position = "none") +
ggplot2::annotate(
geom = "rect",
xmin = -Inf, xmax = Inf, ymin = 1, ymax = alpha,
fill = "firebrick", alpha = 0.2, colour = NA
) +
ggplot2::geom_hline(yintercept = alpha, linetype = 2, colour = "firebrick") +
ggplot2::scale_y_continuous(
trans = pval_trans(alpha = alpha, md = TRUE, colour = "firebrick"),
expand = ggplot2::expansion(mult = c(0, 0.2)),
limits = c(1, NA)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.