如何在R中使用eulerr包绘制Venn图时更改标签位置?

3

我正在尝试使用 R 中的 eulerr 包创建一个缩放的 Venn 图。

我的代码如下:

plot(euler(c( "LUTS"=98, "Symptoms of UTI"=46, "Positive urine culture"=39, 
              "Symptoms of UTI&LUTS"=33, "LUTS&Positive urine culture"=24, 
              "Symptoms of UTI&Positive urine culture"=22, "Symptoms of UTI&LUTS&Positive urine culture"=18),
           input = "union", shape = "ellipse"), key = TRUE, counts = TRUE, 
     quantities = list(type = c("counts", "percent"), font=3, round=2, cex=0.8), 
     fills =list(fill=c(viridis::plasma(n = 3))), alpha = 0.3, c("#1957FF", "#FF750C", "#FF220C"), alpha = 0.3, 
     edges=list(lty = 1), factor_names = TRUE, labels=list(font=2, cex=1), legend = FALSE)


输出结果: enter image description here

我如何让百分比值在计数值下面打印出来?类似这样:

enter image description here

1个回答

2

除非我在文档中漏掉了什么,否则我没有看到这个选项。但是,由于plot.euler生成了一个grob树,我们可以通过一些grob-hacking来编辑输出:

library(eulerr)

v <- plot(euler(c( "LUTS"=98, "Symptoms of UTI"=46, "Positive urine culture"=39, 
              "Symptoms of UTI&LUTS"=33, "LUTS&Positive urine culture"=24, 
              "Symptoms of UTI&Positive urine culture"=22, 
              "Symptoms of UTI&LUTS&Positive urine culture"=18),
           input = "union", shape = "ellipse"), key = TRUE, counts = TRUE, 
     quantities = list(type = c("counts", "percent"), font=3, round=2, cex=0.8), 
     fills =list(fill=c(viridis::plasma(n = 3))), alpha = 0.3, 
     c("#1957FF", "#FF750C", "#FF220C"), alpha = 0.3, 
     edges=list(lty = 1), factor_names = TRUE, labels=list(font=2, cex=1), 
     legend = FALSE)

tags <- v$children[[1]]$children[[1]]$children$tags$children

tags <- do.call(grid::gList, lapply(tags, function(x) {
  x$children[[2]]$label <- sub(" \\(", "\n(", x$children[[2]]$label)
  x$children[[2]]$just <- NULL
  x$children[[2]]$hjust <- 0.5
  x$children[[2]]$vjust <- 1
  x}))

v$children[[1]]$children[[1]]$children$tags$children <- tags

v

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接