Skip to content

Added log transformation argument for color scale #316

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

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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(...))

Expand Down