Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page break (new page) in plots

Tags:

plot

r

ggplot2

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:

enter image description here

like image 244
Ali Avatar asked Jan 04 '13 13:01

Ali


1 Answers

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

like image 159
csgillespie Avatar answered Oct 04 '22 22:10

csgillespie