1

I want to color each segment of a Venn diagram with four conditions according to color scale (see below). However, the colors do not map to the correct sections and are way off from what I want. How can I fix this?

library(ggVennDiagram)
library(ggplot2)

genes <- paste0("gene",1:40)

gene_list <- list(
  A = genes[1:10],
  B = genes[1:20],
  C = genes[5:15],
  D = genes[30:40]
)

colorGroups <- c(A = "#45B6AA", B = "#D45176", C = "#91A6CE", D = "#86AD4C")          
# use colorRampPalette to create function that interpolates colors 
colfunc <- colorRampPalette(colorGroups)
# call function and create vector of 15 colors
col <- colfunc(15)

ggvenn::ggvenn(data = gene_list,
                       fill_alpha = 0.5,
                       fill_color = col,
                       show_percentage = FALSE)

Resulting Venn diagram

The colorRampPalette works as expected, however the colors are not mapped correctly. For example, section C is grey (default), but it should actually be green.

2
  • Any reason you create a color ramp with 15 colors when you have only 4 sets? As a result only the first four colors of your ramp are used, i.e. c("#45B6AA", "#63A09E", "#828A93", "#A07588"). Why not using fill_color = colorGroups?
    – stefan
    Commented Jan 21 at 11:58
  • 1
    Well, now I feel dumb, that was super obvious. Actually, I took this code from a similar question (stackoverflow.com/questions/68875752/…) and figured this is the way to go. Thank you very much!
    – nklskrmr
    Commented Jan 21 at 12:12

0

Browse other questions tagged or ask your own question.