我试图使用带有函数VennDiagram的R draw.pairwise.venn包(v1.6.20)生成一个Venn图,其中:
我有两个类别"Method_1“& "Method_2”(因此是draw.pairwise.venn)
对于Method_2,它的所有标签都包含在Method_1中。
我的问题是,当绘制Venn时,特定于Method_1的标签显示在Venn的右侧,这让人困惑,因为如果您不注意颜色,您可能会认为它们对应于Method_2标签。见图1
Ps :切换类别(将Method_1放在右边)不是一种选择,因为在本研究中,我们生成了许多Venn图,并且总是希望左边有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,因为它的标签在维恩的右边。
$hjust表现得像预期的那样,但$just却不是这样。见图2
str(v[6]) 11人名单 $ label : chr "tata\ntiti“$x:'unit‘num 0.828npc - attr(,"valid.unit")= int 0 - attr(,"unit")= chr "npc“ $y *“单元”num 0.5npc - attr(,"valid.unit")= int 0 - attr(,"unit")= chr "npc“ $ just : chr "centre“ $ hjust :空 $:NULL $ rot : num 0 $ check.overlap: logi $ name : chr "GRID.text.431“ $ gp :5人名单 ..$ col : chr“黑色” ..$ cex : num 1.1 ..$字体: chr“平原” ..$字体家族: chr "serif“ ..$字体:命名为int 1 。。- attr(,“name”)= chr“平原” .- attr(,"class")= chr "gpar“ $ vp :空 - attr(*,"class")= chr 1:3“文本”"grob“"gDesc”
图2的更新:
v[[6]]$hjust <- 17 # Default = NULL
v[[6]]$just <- "left" # Default = "centre"
grid.newpage()
grid.draw(v)
如何强制Method_1标签的“好”左对齐?
发布于 2019-08-02 02:28:06
just
和hjust
基本上是一样的。如果我理解正确,你想要改变标签的位置,独立于理由。您可以使用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 <- "left"
,以实现在v[[6]]
中所需的相对分布。
https://stackoverflow.com/questions/57323441
复制