r - Preventing ggplot2 from cutting off charts in a Sweave PDF -
when generating list of charts using ggplot2, how make sure each chart printed on own page in pdf?
i'm creating script in r sweave (.rnw) file. in script, i'm creating list of on thirty charts using ggplot2 , knitr. second chart code creates 30+ charts using loop. how write each new chart prints on new page?
here's examples of 2 different codes use create charts:
<<benchmarks1,echo=false, results=true, message=false, warning=false>>= library(ggplot2) library(data.table) versions<-unique(testdf[order(testdf$number), ][,2]) testdf <- testdf[complete.cases(testdf),] setdt(testdf) testdf <- testdf[, benchmark := value[category== "time"][which.min(number[category == "time"])], = filename] testdf$version<-factor(testdf$version, levels = versions) testdf$deviation<-testdf$value- testdf$benchmark testdf$deviationp<-(testdf$value- testdf$benchmark)/testdf$benchmark g <-ggplot(subset(testdf, category == 'time') , aes(color = value, x = version, y = deviationp, group = filename)) + geom_line(size=.25) + geom_point(aes(shape = build), size = 1.5) + scale_shape_manual(values=c(1,15)) + ylab("run time deviation benchmark (%)") + scale_colour_gradient(name = 'run time (min)',low = 'blue', high = 'red') + coord_cartesian(ylim=c(-3,7)) + theme(axis.text.x = element_text(size = 10, angle = 90, vjust = .5)) + theme(axis.title.y = element_text(vjust = 1)) + theme(axis.title.x = element_text(vjust = -0.1)) + theme(plot.margin=unit(c(0,0,0,0),"mm")) g @
<<charts, echo=false, results=true, message=false, warning=false>>= library(ggplot2) versions<-unique(testdf[order(testdf$number), ][,2]) testdf$version<-factor(testdf$version, levels = versions) files<-unique(testdf$filename) (i in 1:36){ p <- ggplot(subset(testdf, filename== files[i]), aes(x=version, y=value, group=filename)) p <- p + geom_line(size=.25) + geom_point(shape = 19, size = 1.2, colour = 'red') + scale_shape_manual(values=c(1,15)) + stat_summary(fun.y=sum, geom="line") + ggtitle(files[i]) + facet_grid(category ~ ., scales = "free", space = "fixed") + ylab("value") + xlab("version") + expand_limits(y=0) + theme(axis.text.x = element_text(size = 10, angle = 90, vjust = .5)) + theme(axis.title.y = element_text(vjust = 1)) + theme(axis.title.x = element_text(vjust = -0.1)) + theme(panel.margin = unit(0.3, "lines")) + theme(plot.margin=unit(c(0,0,0,0),"mm")) print(p) } @
i don't think there's reason provide example of data looks like. if think otherwise, let me know in comments.
here's in pdf report:
the bold gray line page break
is there anyway can force ggplot2 print charts on next page? i'd prefer if there way only when 2nd chart won't fit on same page. if reason 2 charts both fit on page, i'd fine having both there.
Comments
Post a Comment