0

I'm trying to create a 5 set Venn Diagram from a lists of lists of differentially expressed genes (after running DESeq2), and because the easy-to-use R packages allows up to 4 sets, I'm using a ggVennDiagram and ggplot2.

I have 5 sets (A, B, C, D, and E) data frames, and I have created a list (either by selecting only the row.names -where the gene names are- or by selecting data$geneNames), and I'm still facing the same error.

    # Verify the length of the Data 
len_deq <- (nrow(DEG_A_list))
len_wide <- (nrow(DEG_B_list))
len_bro <- (nrow(DEG_C_list))
len_varie <- (nrow(DEG_D_list))
len_font <- (nrow(DEG_E_list))

y <- list(
  A = sample(rownames(DEG_A_list), len_deq),
  B = sample(rownames(DEG_B_list), len_wide),
  C = sample(rownames(DEG_C_list), len_bro),
  D = sample(rownames(DEG_D_list), len_varie),
  E = sample(rownames(DEG_E_list), len_font)
)

venn <- Venn(y)
data <- process_data(venn)

ggplot() +
 geom_sf(aes(fill=id), data = venn_region(data), show.legend = FALSE) +
 geom_sf(color="grey", size = 3, data = venn_setedge(data), show.legend = FALSE) +
 geom_sf_text(aes(label = name), fontface = "bold", data = venn_setlabel(data)) +
 geom_sf_label(aes(label = name), data = venn_region(data), alpha = 0.5) + 
 theme_void()

And here's the error:

Error in `geom_sf()`:
! Problem while computing stat.
ℹ Error occurred in the 1st layer.
Caused by error in `compute_layer()`:
! `stat_sf()` requires the following missing aesthetics: geometry
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `geom_sf()`:
! Problem while computing stat.
ℹ Error occurred in the 1st layer.
Caused by error in `compute_layer()`:
! `stat_sf()` requires the following missing aesthetics: geometry
---
Backtrace:
     ▆
 1. ├─base (local) `<fn>`(x)
 2. └─ggplot2:::print.ggplot(x)
 3.   ├─ggplot2::ggplot_build(x)
 4.   └─ggplot2:::ggplot_build.ggplot(x)
 5.     └─ggplot2:::by_layer(...)
 6.       ├─rlang::try_fetch(...)
 7.       │ ├─base::tryCatch(...)
 8.       │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
 9.       │ │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 10.       │ │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 11.       │ └─base::withCallingHandlers(...)
 12.       └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
 13.         └─l$compute_statistic(d, layout)
 14.           └─ggplot2 (local) compute_statistic(..., self = self)
 15.             └─self$stat$compute_layer(data, self$computed_stat_params, layout)
 16.               └─ggplot2 (local) compute_layer(..., self = self)
 17.                 └─ggproto_parent(Stat, self)$compute_layer(data, params, layout)
 18.                   └─ggplot2 (local) compute_layer(..., self = self)

Any idea on what I'm doing wrong? Thanks!!!!

1
  • You need to add a geometry argument into your geom_sf() call. Beyond that, please make your code reproducible by providing some example data. Please see the function's help page to get more information about that argument by running ?geom_sf
    – Phil
    Commented Feb 1 at 3:44

2 Answers 2

0

for everyone experience something similar- I was able to solve the 5 set Venn Diagram issue using other package: VennDiagram. It is very customizable but you will have to calculate the interaction of your groups manually. Here's an example currently working great:

library(VennDiagram)
# Creating the data frames
area1 <- sample(DEG_A$geneName)
area2 <- sample(DEG_B$geneName)
area3 <- sample(DEG_C$geneName)
area4 <- sample(DEG_D$geneName)
area5 <- sample(DEG_E$geneName)

# Calculating the numbers 
length(area1) # 9575
length(area2) # 4253
length(area3) #  8438
length(area4) # 6429
length(area5) # 5811 

# Calculating the intersections
n12 <- Reduce(intersect, list(area1, area2))
#length(n12) # 3825
n13 <- Reduce(intersect, list(area1, area3))
#length(n13) # 6723
n14 <- Reduce(intersect, list(area1, area4))
#length(n14) # 5784
n15 <- Reduce(intersect, list(area1, area5))
#length(n15) # 4992
n23 <- Reduce(intersect, list(area2, area3))
#length(n23) # 3839
n24 <- Reduce(intersect, list(area2, area4))
#length(n24) # 3154
n25 <- Reduce(intersect, list(area2, area5))
#length(n25) # 2757
n34 <- Reduce(intersect, list(area3, area4))
#length(n34) # 4719
n35 <- Reduce(intersect, list(area3, area5))
#length(n35) # 4313
n45 <- Reduce(intersect, list(area4, area5))
#length(n45) # 4242
n123 <- Reduce(intersect, list(area1, area2, area3))
#length(n123) #3575
n124 <- Reduce(intersect, list(area1, area2, area4))
#length(n124) # 3092
n125 <- Reduce(intersect, list(area1, area2, area5))
#length(n125) # 2667
n134 <- Reduce(intersect, list(area1, area3, area4))
#length(n134) # 4532
n135 <- Reduce(intersect, list(area1, area3, area5))
#length(n135) # 4080
n145 <- Reduce(intersect, list(area1, area4, area5))
#length(n145) # 4063
n234 <- Reduce(intersect, list(area2, area3, area4))
#length(n234) # 2977
n235 <- Reduce(intersect, list(area2, area3, area5))
#length(n235) # 2638
n245 <- Reduce(intersect, list(area2, area4, area5))
#length(n245) # 2420
n345 <- Reduce(intersect, list(area3, area4, area5))
#length(n345) # 3506
n1234 <- Reduce(intersect, list(area1, area2, area3, area4))
#length(n1234) # 2931
n1235 <- Reduce(intersect, list(area1, area2, area3, area5))
#length(n1235) # 2576
n1245 <- Reduce(intersect, list(area1, area2, area4, area5))
#length(n1245) # 2399
n1345 <- Reduce(intersect, list(area1, area3, area4, area5))
#length(n1345) # 3454
n2345 <- Reduce(intersect, list(area2, area3, area4, area5))
#length(n2345) # 2344
n12345 <- Reduce(intersect, list(area1, area2, area3, area4, area5))
#length(n12345) # 2327

venn.plot <- draw.quintuple.venn(
  area1 = 9575,
  area2 = 4253,
  area3 = 8438,
  area4 = 6429,
  area5 = 5811,
  n12 = 3825,
  n13 = 6723,
  n14 = 5784,
  n15 = 4992,
  n23 = 3839,
  n24 = 3154,
  n25 = 2757,
  n34 = 4719,
  n35 = 4313,
  n45 = 4242,
  n123 = 3575,
  n124 = 3092,
  n125 = 2667,
  n134 = 4532,
  n135 = 4080,
  n145 = 4063,
  n234 = 2977,
  n235 = 2638,
  n245 = 2420,
  n345 = 3506,
  n1234 = 2931,
  n1235 = 2576,
  n1245 = 2399,
  n1345 = 3454,
  n2345 = 2344,
  n12345 = 2327,
  category = c("A", "B", "C", "D", "E"),
  fill = c("white", "black", "yellow", "green","red"),
  cat.col = c("white", "black", "yellow", "green","red"),
  cat.cex = 2,
  margin = 0.05,
  cex = c(1.5, 1.5, 1.5, 1.5, 1.5, 1, 0.8, 1, 0.8, 1, 0.8, 1, 0.8, 1,         0.8,
      1, 0.55, 1, 0.55, 1, 0.55, 1, 0.55, 1, 0.55, 1, 1, 1, 1, 1, 1.5),
  ind = TRUE
)

I'm sure there are easiest and more beautiful ways to do the same, but this is what I could solve with my scarce coding skills.

Thanks :)

0

The manual for ggVennDiagram has recently been updated and can be found at this link. In short, the geom_sf() function should be replaced with geom_polygon() and so on...

Not the answer you're looking for? Browse other questions tagged or ask your own question.