如何手动修改绘图中的自动编号和标签

How to manually modify automated numbers and labels in plot

我正在 library(eulerr) 中使用 euler() 绘制维恩图。我想修改自动绘图输出。

我用这段代码生成图:

VennDiag <- euler(c("A" = 1.8, "B" = 1.5, "C" = 10.6, "A&B" = 0, "B&C" = 3.0, 
                    "A&C" = 1.1, "A&B&C" = 1.2))

plot(VennDiag, counts = TRUE, fontface = "bold", cex=2, fill_alpha=0.7, fill=c("darkgrey", "grey", "lightgrey"),
     col="black", lty = 1, lwd = 3, auto.key = F, labels=c("le","Et","Se"))
grid::grid.text("Residual variance: 80.8%", x=0.83, y=0.12, gp=gpar(col="black", fontsize=18, fontface=1))
grid::grid.text("9.6%", x=0.53, y=0.82, gp=gpar(col="black", fontsize=18, fontface=1)) # A = LU
grid::grid.text("7.8%", x=0.19, y=0.62, gp=gpar(col="black", fontsize=18, fontface=1)) # B = Env
grid::grid.text("55.1%", x=0.63, y=0.29, gp=gpar(col="black", fontsize=18, fontface=1)) # C = Space
grid::grid.text("0%", x=0.39, y=0.77, gp=gpar(col="black", fontsize=18, fontface=1)) # AB
grid::grid.text("5.8%", x=0.63, y=0.72, gp=gpar(col="black", fontsize=18, fontface=1)) # AC
grid::grid.text("15.5%", x=0.28, y=0.45, gp=gpar(col="black", fontsize=18, fontface=1)) # BC
grid::grid.text("6.4%", x=0.47, y=0.63, gp=gpar(col="black", fontsize=18, fontface=1)) # ABC
dev.off()

图形是这样的:

我希望看到的更改很少:

首先,我想增加自动绘制数字的大小,即“10.6”、“1.8”等

其次,我想控制三个圆标签的位置。

那么,我想减少整体的plot margin,也就是减少白色。

最后,如何防止图表在每次重新绘制时改变其位置,即避免它在 space 中旋转(这会导致手动添加的 % 数字出现问题)。

这是 VennDiag 的 dput():

> dput(VennDiag)
structure(list(coefficients = structure(c(0.0223077882736185, 
-1.10120243622206, 0.21452780830607, 1.57628687088998, 0.499982912317244, 
-0.493383431185427, 1.16845462595081, 1.36468343773937, 2.25135806565536
), .Dim = c(3L, 3L), .Dimnames = list(c("A", "B", "C"), c("x", 
"y", "r"))), original.values = structure(c(1.8, 1.5, 10.6, 0, 
1.1, 3, 1.2), .Names = c("A", "B", "C", "A&B", "A&C", "B&C", 
"A&B&C")), fitted.values = structure(c(1.7761271295339, 1.47090356084969, 
10.5965224775034, 0.210495232193053, 1.15761484399341, 3.02444455156862, 
1.14493593079205), .Names = c("A", "B", "C", "A&B", "A&C", "B&C", 
"A&B&C")), residuals = structure(c(0.0238728704661046, 0.0290964391503143, 
0.00347752249660971, -0.210495232193053, -0.057614843993411, 
-0.0244445515686209, 0.0550640692079498), .Names = c("A", "B", 
"C", "A&B", "A&C", "B&C", "A&B&C")), region_error = structure(c(0.00210750878001437, 
0.00223107077659614, 0.00533659321579116, 0.0108608821673497, 
0.0024375646550976, 0.000198313916472209, 0.0034249601335735), .Names = c("A", 
"B", "C", "A&B", "A&C", "B&C", "A&B&C")), diag_error = 0.0108608821673497, 
    stress = 0.000406841007934756), .Names = c("coefficients", 
"original.values", "fitted.values", "residuals", "region_error", 
"diag_error", "stress"), class = c("euler", "list"))

First, I would like to increase the size of the automatically plotted numbers, i.e. '10.6', '1.8' etc

您可以为 counts 参数提供一个仅用于修改这些标签的选项列表,例如 plot(fit, counts = list(cex = 3))

Second, I would like to control the position of the three circle labels.

您可能可以使用 lattice::trellis.focus() 实现此目的,但使用 inkscape 或 illustrator 可能更容易解决此问题。

Then, I would like to reduce the overall plot margin, i.e. have less white.

这种白色有两个来源。第一个是绘图区域内的填充,您可以使用 xlimylim 参数对其进行修改。第二个是绘图周围的填充,您可以使用 par.settings 参数进行调整。例如,参见 this

Finally, how can I prevent the graph to change its position every time I re-plot it, i.e. avoid that it rotates in space (which then causes an issue with the manually added % numbers).

使用set.seed().