From 48b95e2c573e2cb4398ae0d74a2d497d621be264 Mon Sep 17 00:00:00 2001 From: ThomasKAtkins <32600420+ThomasKAtkins@users.noreply.github.com> Date: Wed, 26 Mar 2025 14:29:18 -0400 Subject: [PATCH] Added log transformation argument for color scale --- DESCRIPTION | 2 +- R/utilities.R | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a271543..899abd4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,7 @@ Imports: DOSE (>= 3.31.2), ggfun (>= 0.1.7), ggnewscale, - ggplot2, + ggplot2 (>= 3.5.0), ggrepel (>= 0.9.0), ggtangle (>= 0.0.5), graphics, diff --git a/R/utilities.R b/R/utilities.R index 241495b..8a040e6 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -19,7 +19,7 @@ get_enrichplot_color <- function(n = 2) { if (n != 2 && n != 3) stop("'n' should be 2 or 3") - colors = c("#e06663", "#327eba") + colors = c("#ec2b54", "#005087") if (n == 2) return(colors) if (n == 3) return(c(colors[1], "white", colors[2])) @@ -34,6 +34,7 @@ get_enrichplot_color <- function(n = 2) { ##' @param name name of the color legend ##' @param .fun force to use user provided color scale function ##' @param reverse whether reverse the color scheme, default is TRUE as it is more significant for lower pvalue +##' @param log_transform whether or not to log-transform the color scale, default is TRUE as p-values operate over a wide range of orders of magnitude ##' @param ... additional parameter that passed to the color scale function ##' @return a color scale ##' @importFrom ggplot2 scale_fill_continuous @@ -42,7 +43,8 @@ get_enrichplot_color <- function(n = 2) { ##' @importFrom ggplot2 scale_color_gradientn ##' @export set_enrichplot_color <- function(colors = get_enrichplot_color(2), - type = "color", name = NULL, .fun = NULL, reverse=TRUE, ...) { + type = "color", name = NULL, .fun = NULL, + reverse = TRUE, log_transform = TRUE, ...) { type <- match.arg(type, c("color", "colour", "fill")) if (!reverse) colors = rev(colors) @@ -77,6 +79,9 @@ set_enrichplot_color <- function(colors = get_enrichplot_color(2), params$guide <- guide_colorbar(reverse=reverse, order=1) params$name <- name # no legend name setting by default as 'name = NULL' + if (log_transform) { + params$transform <- "log10" + } params <- modifyList(params, list(...))