[R] Sweave: infelicities with lattice graphics

Michael Friendly friendly at yorku.ca
Sun Sep 12 17:41:57 CEST 2010


Just a follow-up on this thread, now with R 2.11.1.  I was happy back 
then to use Deepayan's solution for this, under earlier R versions; but 
it now gives an error and the Sweave-generated .tex file no longer compiles.

<<ortho-xyplot1-code, keep.source=TRUE, eval=FALSE>>=
library(nlme)
library(lattice)
xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, 
pch=15:25,
     col=palette(), cex=1.3, main="Orthodont data")
@
<<ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6>>=
plot(trellis.last.object())
@

Now, I get the following from Sweave:

Error:  chunk 46 (label=ortho-xyplot1)
Error in !lattice.getStatus("current.plot.saved", prefix = prefix) :
   invalid argument type

Did something in lattice change so that plot(trellis.last.object()) no 
longer works or needs to be specified differently?

-Michael



On 7/16/2010 1:14 AM, Deepayan Sarkar wrote:
> On Thu, Jul 15, 2010 at 1:51 PM, Michael Friendly<friendly at yorku.ca>  wrote:
>> In a paper I'm writing using Sweave, I make use of lattice graphics, but
>> don't want to explicitly show (or explain)
>> in the article text the print() wrapper I need in code chunks for the graphs
>> to appear. I can solve this by including each chunk twice, with different
>> options, as in
>>
>> <<ortho-xyplot1-code, keep.source=TRUE, eval=FALSE>>=
>> library(nlme)
>> library(lattice)
>> xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject,
>> pch=15:25,
>>    col=palette(), cex=1.3, main="Orthodont data")
>> @
>> <<ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6>>=
>> library(nlme)
>> library(lattice)
>> print(xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject,
>> pch=15:25,
>>    col=palette(), cex=1.3, main="Orthodont data"))
>> @
>>
>> but then, if I decide to change the plotting code, I have to make changes in
>> two places.  Is there some
>> feature of Sweave or lattice I've missed that would simplify this? Re-use of
>> code chunks doesn't seem
>> to apply here.
>
> I usually use this variant of Duncan's suggestion:
>
> <<ortho-xyplot1-code, keep.source=TRUE, eval=FALSE>>=
> library(nlme)
> library(lattice)
> xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25,
>    col=palette(), cex=1.3, main="Orthodont data")
> @
>
> <<ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6>>=
> plot(trellis.last.object())
> @
>
> -Deepayan
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA



More information about the R-help mailing list