【问题标题】:Force label to the left in VennDiagram在 VennDiagram 中将标签强制向左
【发布时间】:2019-12-10 21:39:17
【问题描述】:

我正在尝试使用 R VennDiagram 包 (v 1.6.20) 生成维恩图,函数 draw.pairwise.venn,其中:

我有两个类别“Method_1”和“Method_2”(因此 draw.pairwise.venn)
对于 Method_2,它的所有标签都包含在 Method_1 中。

我的问题是,在绘制维恩时,特定于 Method_1 的标签显示在维恩的右侧,这令人困惑,因为如果您不注意颜色,您可能会认为它们对应于 Method_2 标签. See figure 1

Ps:切换类别(将 Method_1 放在右侧)不是一种选择,因为在这项研究中,我们生成了许多维恩图,并且希望始终将 Method_1 放在左侧,Method_2 放在右侧。

图 1 的代码:

M1 <- c("toto", "tata", "titi")
M2 <- "toto"
if (all(M2 %in% M1)) {
    v <- draw.pairwise.venn(
      area1 = 100,
      area2 = 35,
      cross.area = 35,
      category = c("Method_1", "Method_2"),
      fill = c("navajowhite", "lightskyblue1"),
      lty = "blank",
      cex = 1.1,
      cat.cex = 2.1,
      cat.dist = c(0.03, 0.112),
      cat.pos = c(330, 30),
      margin = 0.04,
      cat.col = c("sienna4", "darkblue")
    )

    v[[5]]$label <- paste(intersect(M1, M2), collapse = "\n")
    v[[6]]$label <- paste(setdiff(M1, M2), collapse = "\n")
    grid.newpage()
    grid.draw(v)
}

我确实尝试过使用 $hjust 和 $just 来处理 Venn 右侧的标签。
$hjust 的行为与 ~ 预期的一样,但 $just 的情况并非如此。 See figure 2

> str(v[[6]])
11 个列表
$ label : chr "tata\ntiti"
$ x : 'unit' num 0.828npc
..- attr(, "valid.unit")= int 0
..- attr(
, "unit")= chr "npc"
$ y
: 'unit' num 0.5npc
..- attr(, "valid.unit")= int 0
..- attr(
, "unit")= chr "npc"
$ just : chr "centre"
$ hjust : NULL
$ vjust : NULL
$ rot : num 0
$ check.overlap: logi FALSE
$ name : chr "GRID.text.431"
$ gp : 5 个列表
..$ col : chr "black"
..$ cex : num 1.1
..$ fontface : chr "plain"
..$ fontfamily: chr "serif"
..$ font : 命名为 int 1
.. ..- attr(, "names")= chr "plain"
..- attr(
, "class")= chr "gpar"
$ vp : NULL
- attr(*, "class")= chr [1:3] "text" "grob" "gDesc"

图 2 的更新:

v[[6]]$hjust <- 17 # Default = NULL
v[[6]]$just <- "left" # Default = "centre"
grid.newpage()
grid.draw(v)

如何强制 Method_1 标签“良好”左对齐?

【问题讨论】:

    标签: r venn-diagram


    【解决方案1】:

    justhjust 基本相同。如果我理解正确,你想改变标签的位置,独立于理由。您可以使用 x 变量来做到这一点:

    M1 <- c("toto", "tata", "titi")
    M2 <- "toto"
    if (all(M2 %in% M1)) {
        v <- draw.pairwise.venn(
          area1 = 100,
          area2 = 35,
          cross.area = 35,
          category = c("Method_1", "Method_2"),
          fill = c("navajowhite", "lightskyblue1"),
          lty = "blank",
          cex = 1.1,
          cat.cex = 2.1,
          cat.dist = c(0.03, 0.112),
          cat.pos = c(330, 30),
          margin = 0.04,
          cat.col = c("sienna4", "darkblue")
        )
    
        v[[5]]$label <- paste(intersect(M1, M2), collapse = "\n")
        v[[6]]$label <- paste(setdiff(M1, M2), collapse = "\n")
        v[[6]]$just <- "left"
        v[[6]]$x <- unit(0.15, 'npc')
        grid.newpage()
        grid.draw(v)
    }
    

    您可以更改或删除v[[6]]$just &lt;- "left" 行,以在v[[6]] 中实现您想要的相对分布。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-26
      • 2015-01-31
      • 2014-06-21
      • 2016-05-29
      相关资源
      最近更新 更多