While diverting output of the plot to a PDF (or other) file, how to make page break, such that the new plot is forced to be drawn on a new page?
Using normal plot()
or ggplot()
functions automatically draws new plot on a new page. However
I am using package VennDiagram
to draw some Venn charts. The problem is that when I try to make several diagrams, all of them are plotted on the same page:
library("VennDiagram")
pdf("foo.pdf")
draw.pairwise.venn(area1 = 100, area2 = 100, cross.area = 20,
category = c("A", "B"), fill = c("blue", "red"), lty = "blank")
draw.pairwise.venn(area1 = 200, area2 = 200, cross.area = 100,
category = c("C", "D"), fill = c("blue", "red"), lty = "blank")
dev.off()
Here is the result, while I want to separate plots on different pages:
You can force a new page using grid.newpage()
pdf("foo.pdf")
draw.pairwise.venn(area1 = 100, area2 = 100, cross.area = 20,
category = c("A", "B"), fill = c("blue", "red"), lty = "blank")
grid::grid.newpage()
draw.pairwise.venn(area1 = 200, area2 = 200, cross.area = 100,
category = c("C", "D"), fill = c("blue", "red"), lty = "blank", add=FALSE)
dev.off()
Essentially, VennDiagram
uses grid graphics to handle the drawing aspect. So, we just force a new graph to be created using grid.newpage()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With