YuLab-SMU / enrichplot

Visualization of Functional Enrichment Result
https://yulab-smu.top/biomedical-knowledge-mining-book/
232 stars 65 forks source link

cnetplot: allow setting ranges for fold change color scale #39

Closed lbeltrame closed 4 years ago

lbeltrame commented 4 years ago

Currently the calculation of the color scale is set automagically:

https://github.com/YuLab-SMU/enrichplot/blob/17dd93f05167ebfadf7f50bab9ba88a8f6b398ef/R/cnetplot.R#L73

The problem is that if the supplied fold change vector is skewed (e.g., no down-regulated genes) you get images that are highly misleading from a biological standpoint. A better solution would be to optionally allow to set min, max, and center.

huerqiang commented 4 years ago

Thank you very much for your correction! Could you please provide the repeatable code to make the problematic diagram? We will adjust the code according to the diagram.

lbeltrame commented 4 years ago
library(enrichplot)
library(ReactomePA)

gene <- c("11171", "8243", "112464", "2194",
                             "9318", "79026", "1654", "65003",
                             "6240", "3476", "6238", "3836",
                             "4176", "1017", "249")
yy = enrichPathway(gene, pvalueCutoff=0.05)
# Random numbers between 0 and 1, put all negative - simulate log2FC
fold_changes <- -1 * rbeta(length(gene), 1, 1)
names(fold_changes) = gene
# Set one single gene to be slightly up-regulated - this one is shown in the plot later
fold_changes[14] <- 0.01
cnetplot(yy, foldChange=fold_changes)

What you see is this:

Screenshot_20200219_091117

Notice where the midpoint is? -0.4 in this case. When you have a lot of genes, and you have an up-regulated:down-regulated ratio that is skewed, the colors may become misleading. Example, if I had a gene at -0.4, a quick look might fool me thinking that is not regulated, except it is not the case.

GuangchuangYu commented 4 years ago

fixed by https://github.com/YuLab-SMU/enrichplot/pull/40.