0

I am plotting a Venn diagram using euler() in library(eulerr). I would like to modify the automated plot output.

I use this code to produce the figure:

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

The figure looks like this:

enter image description here

There are few things that I would like to see changed:

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

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

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

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

This is the dput() for VennDiag:

> 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"))
zx8754
  • 52,746
  • 12
  • 114
  • 209
tabtimm
  • 411
  • 3
  • 6
  • 17

1 Answers1

1

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

You can provide the countsargument with a list of options that will be just to modify these labels, such as plot(fit, counts = list(cex = 3)).

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

You could probably achieve this using lattice::trellis.focus() but it would probably be easier to just fix this using inkscape or illustrator.

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

There are two sources of this white. The first is padding inside the plot region, which you could modify with xlim and ylim arguments. The second is the padding around the plot, which you can adjust with the par.settings argument. See this for instance.

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

Use set.seed().

Johan Larsson
  • 3,496
  • 18
  • 34
  • The `counts = list(cex = 3)` worked really well, thanks. – tabtimm Oct 21 '17 at 13:52
  • I am embedding my `plot()` code within `tiff(file = "Fig", height=8,....)` and `dev.off()`. In which place should the `set.seed()` be, after `tiff(file...)` or before? Does `set.seed()` require some sort of closure command after the particular plot for which it is intended, or does it automatically only refer to this particular plot? Thank you. – tabtimm Oct 21 '17 at 14:21
  • `set.seed(4)` (4 is just an example, you can use whatever integer) uses a pre-defined table of "pseudo-random" numbers. You only need to call it once and it does not matter if it is before or after the device is called. You don't need any closure command. – Johan Larsson Oct 21 '17 at 14:25