[R] Raster images from sweave

Roger Bivand Roger.Bivand at nhh.no
Fri Sep 24 19:36:54 CEST 2004


On Fri, 24 Sep 2004, hadley wickham wrote:

> Is it possible to get sweave to produce raster (eg. png/jpg) plot
> images?  I'm writing a vignette that contains plots with tens of
> thousands of points which results in very large pdf files (13 megs
> before compression).

Yes. I do it by including these chunks after \begin{document}

<<echo=FALSE>>= 
.PngNo <- 0
@

<<label=afig,echo=FALSE,eval=FALSE>>= 
.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", .PngNo, ".png", sep="")
png(file=file, width = 1200, height = 1200, pointsize = 24, bg = "white")
@

<<label=zfig,echo=FALSE,eval=FALSE>>= 
dev.null <- dev.off()
cat("\\includegraphics{", file, "}\n\n", sep="")
@

then for each figure e.g.:

<<label=quad,echo=FALSE,eval=FALSE>>= 
plot(drumlin.xy)
@

\begin{scriptsize}
<<fig=FALSE,echo=TRUE, eval=FALSE>>= 
<<quad>>
@ 
\end{scriptsize}

\begin{center} 
<<results=tex,echo=FALSE>>= 
<<afig>>
<<quad>>
<<zfig>>
@ 
\end{center}

maybe putting the graphic in a figure environment if it is not just a 
slide. I find I need to hand tune the output resultion and pointsize 
depending on the output medium.

Roger Bivand

> 
> Thanks,
> 
> Hadley
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list