[R] Sweave: include a multi-page-pdf plot

Duncan Murdoch murdoch.duncan at gmail.com
Sun Mar 27 20:40:19 CEST 2011


On 27/03/2011 1:12 PM, Alexander Engelhardt wrote:
> Hi,
> I'm just starting out with Sweave, and I can't get a plot(linmod) to
> display all four plots:
>
> <<  bild>>=
> x1<- runif(100)
> x2<- rexp(100)
> y<- 3 + 4*x1 + 5*x2 + rnorm(100)
>
> mod<- lm(y~x1+x2)
> plot(mod)
> @
>
> Some Text
>
> <<fig=TRUE>>=
> <<bild>>
> @
>
> This plots only the first image of the four-page plot.lm() result.
> I don't want to use par(mfrow=c(2,2)), but ideally I'd like to access
> each one of the four plots in a different section of my LaTeX-file.
>
> Can you tell me how to do this?

If you want 4 separate pages, you need 4 separate plots.  You should 
change your code from plot(mod) to plot(mod, which=1), and then have 3 
more code chunks containing

plot(mod, which=n)

where n is a number from 2 to 6.  (The default is to use 2, 3, and 5.)

Duncan Murdoch



More information about the R-help mailing list