ggplot2 - R + ggplot: plotting over multiple pages -
I am trying to write a function that plots a ggplot facet_wrap
plot on multiple pages Does. This is just a hack, because this feature is in the ggplot2 feature to-do list. To find out the number of pages I need, do some minor calculations, the number of rows of my data.frame
for which I need per page etc. I'm pretty sure that all this works (slices = CEC ((i-1) * num_rows) +1, (i * num_rows)) for fragment = piece
pdf (filename ) (Seq (num_pages) in i) [(slashes & gt; nrow (df.merged))] df.segment = df.merged [piece,] P < - ggplot (df.segment, aes (y = means, x = phenotype)) P < - p + Geom_bar (stat = "identity", fill = "white", color = "black") p + facet_wrap ("id", scales = "free_y", ncol = n_facets, nrow = n_facets)} dev.off ( )
My problem is that, by wrapping it in one for this loop, pdf ()
and dev.off ()
Function is that ggplot is not waiting for it to loop, and it blazes very quickly through its loop and outputs an invalid pdf.
If I set i = 1
, then start pdf ()
, run the code above the loop, then i = 2
, then run the code, and as long as I'm not bored ( i = 3
), then close the device, which results in a PDF very good
Is there a way that I can wait for the last line before moving on to the next loop?
I think the problem is that for your previous line (P + ...) Print is required so that it can actually be printed on the device inside the loop. . .
Comments
Post a Comment