I started using Sweave some time ago. However, like most people, I pretty soon ran into a serious problem: speed. Wetting a large document takes time to start, which makes efficient work a rather difficult task. Cache can significantly speed up data processing. However, the plots - especially ggplot;) - still take too much time to render. That I want to use pgfSweave.
After many, many hours, I finally managed to create a working system with Eclipse / StatET / Texlipse. Then I wanted to convert the existing report for use with pgfSweave and had a nasty surprise: most of my ggplots seem to no longer work. The following example, for example, works fine in the console and Sweave:
pl <- ggplot(plot_info,aes(elevation,area)) pl <- pl + geom_point(aes(colour=que_id)) print(pl)
By running it with pgfSweave, I get this error:
Error in if (width > 0) { : missing value where TRUE/FALSE needed In addition: Warning message: In if (width > 0) { : the condition has length > 1 and only the first element will be used Error in driver$runcode(drobj, chunk, chunkopts) : Error in if (width > 0) { : missing value where TRUE/FALSE needed
When I remove aes (...) from geom_point, the plot works fine with pgfSweave.
pl <- ggplot(plot_info,aes(elevation,area)) pl <- pl + geom_point() print(pl)
Edit: I investigated the problem more and could reduce the problem to a tikz device.
This works great:
quartz() pl <- ggplot(plot_info,aes(elevation,area)) pl <- pl + geom_point(aes(colour=que_id)) print(pl)
This gives the error above:
tikz( 'myPlot.tex',standAlone = T ) pl <- ggplot(plot_info,aes(elevation,area)) pl <- pl + geom_point(aes(colour=que_id)) print(pl) dev.off()
This works great:
tikz( 'myPlot.tex',standAlone = T ) pl <- ggplot(plot_info,aes(elevation,area)) pl <- pl + geom_point() print(pl) dev.off()
I could repeat this with 5 different ggplots. If the display does not use color (or size, alpha, ...), it works with tikz.
Q1: Does anyone have an explanation for this behavior?
In addition, caching snippets of code without a section does not work very well. The following code snippet does not require time on Sweave. With pgfSweave, it takes about 10 seconds.
<<plot.opts,echo=FALSE,results=hide,cache=TRUE>>= #colour and plot options are globally set pal1 <- brewer.pal(8,"Set1") pal_seq <- brewer.pal(8,"YlOrRd") pal_seq <- c("steelblue1","tomato2") opt1 <- opts(panel.grid.major = theme_line(colour = "white"),panel.grid.minor = theme_line(colour = "white")) sca_fill_cont_opt <- scale_fill_continuous(low="steelblue1", high="tomato2") ory <- geom_hline(yintercept=0,alpha=0.4,linetype=2) orx <- geom_vline(xintercept=0,alpha=0.4,linetype=2) ts1 <- 2.3 ts2 <- 2.5 ts3 <- 2.8 ps1 <- 6 offset_x <- function(x,y) 0.15*x/pmax(abs(x),abs(y)) offset_y <- function(x,y) 0.05*y/pmax(abs(x),abs(y)) plot_size <- 50*50
This is also a rather strange behavior, since only some variables are set for later use.
Q2: Does anyone have an explanation?
Q3: More generally, I would like to ask if anyone is using pgfSweave successfully? With successful, I mean that all the things that work in Sweave also work in pgfSweave, with the added benefit of good fonts and improved speed .;)
Thanks so much for the answers!