2
votes

I am trying to produce a Venn diagram using the R VennDiagram package (v 1.6.20), with function draw.pairwise.venn, where :

I have two categories "Method_1" & "Method_2" (thus draw.pairwise.venn)
For Method_2, all of its labels are included in Method_1.

My issue is that when drawing the Venn, labels which are specific to Method_1 are displayed on the right part of the Venn, which is confusing because if you don't pay attention to colors, you might think they correspond to Method_2 labels. See figure 1

Ps : Switching categories (putting Method_1 on the right) is not an option because in this study we produce many Venn diagrams and want to always have Method_1 on the left and Method_2 on the right.

Code for figure 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)
}

I did try to toy with $hjust & $just for the labels on the right part of the Venn.
$hjust is behaving as ~ expect, but this is not the case for $just. See figure 2

> str(v[[6]])
List of 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 :List of 5
..$ col : chr "black"
..$ cex : num 1.1
..$ fontface : chr "plain"
..$ fontfamily: chr "serif"
..$ font : Named int 1
.. ..- attr(, "names")= chr "plain"
..- attr(
, "class")= chr "gpar"
$ vp : NULL
- attr(*, "class")= chr [1:3] "text" "grob" "gDesc"

Updates for figure 2 :

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

How to force "good" left alignment for Method_1 labels ?

1

1 Answers

1
votes

just and hjust do basically the same. If I understand correctly, you want to change the position of the label, independently of the justification. You can do that with the x variable:

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)
}

Changing label positions in Venndiagram

You can change or eliminate the line v[[6]]$just <- "left" to achieve the relative distribution you want in v[[6]].