从R中的“Eulerr”生成的VennDiagram中删除大小为0的交集

aiqt4smr  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(97)

试图使用包“Eulerr”在R中绘制比例VennDiagram。然而,这个包产生的交集大小为“0”,我想删除。
在R中重现问题的代码

library(eulerr)
gene_list = list("A" = c("a", "b", "c", "d"),
                 "B" = c("a", "b"),
                 "C" = c("d", "e", "f"))
p <- plot(euler(gene_list),
          quantities = list(type = c("counts"), cex=3),
          labels=list(cex=3))
p

我得到的输出:

但我想要的是

当“A”和“C”不重叠时,此软件包会执行我想要的操作

library(eulerr)
gene_list = list("A" = c("a", "b", "c", "d"),
                 "B" = c("a", "b"),
                 "C" = c("e", "f"))
p <- plot(euler(gene_list),
          quantities = list(type = c("counts"), cex=3),
          labels=list(cex=3))
p

当“A”和“C”不相交时有效:

但我想从输出图中删除大小为0的区域,即使“A”和“C”重叠。

3vpjnl9f

3vpjnl9f1#

我可以提供以下解决方案:

for(i in seq_along(p$children$canvas.grob$children$diagram.grob.1$children$tags$children)){
   o <- p$children$canvas.grob$children$diagram.grob.1$children$tags$children[[paste0("tag.number.", i)]]
   if(!is.null(o)){
     if ( o$children[[paste0("tag.quantity.",i)]]$label == 0){ 
       o$children[[paste0("tag.quantity.",i)]]$label <- " "
       p$children$canvas.grob$children$diagram.grob.1$children$tags$children[[paste0("tag.number.", i)]] <- o
     }
   }
 }
 p

结果(零被抑制):

相关问题