Re: [R] Sweave: infelicities with lattice graphics

2010-09-12 Thread Michael Friendly
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 Friendlyfrien...@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@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 StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
R-help@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.


Re: [R] Sweave: infelicities with lattice graphics

2010-09-12 Thread Duncan Murdoch

On 12/09/2010 11:41 AM, Michael Friendly wrote:
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?


I don't know if something in lattice has changed, but that doesn't look 
as though it should work:  the code to do the plot was never evaluated. 
 I think you would need eval=TRUE in the first chunk, or

ortho-xyplot1-code
ahead of the plot command in the second.

Duncan Murdoch



-Michael



On 7/16/2010 1:14 AM, Deepayan Sarkar wrote:

On Thu, Jul 15, 2010 at 1:51 PM, Michael Friendlyfrien...@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@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.





__
R-help@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.


Re: [R] Sweave: infelicities with lattice graphics

2010-09-12 Thread Deepayan Sarkar
On Sun, Sep 12, 2010 at 8:47 AM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 On 12/09/2010 11:41 AM, Michael Friendly wrote:

 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?

 I don't know if something in lattice has changed, but that doesn't look as
 though it should work:  the code to do the plot was never evaluated.  I
 think you would need eval=TRUE in the first chunk, or
 ortho-xyplot1-code
 ahead of the plot command in the second.

Yes. I notice that it was me who introduced the eval=FALSE (I'm not
sure why). Hopefully that should fix it.

However, there _has_ been a recent lattice update, where the internals
have undergone some change, so there is a chance that is to blame. I
won't be able to take a look before day after tomorrow.

-Deepayan

__
R-help@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.


Re: [R] Sweave: infelicities with lattice graphics

2010-09-12 Thread Michael Friendly
Thanks Deepayan and Duncan.  The eval=FALSE was the problem, rather than 
anything with

lattice. Not sure why that worked earlier, but I no longer care.
-Michael


Deepayan Sarkar wrote:

On Sun, Sep 12, 2010 at 8:47 AM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
  

On 12/09/2010 11:41 AM, Michael Friendly wrote:


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?
  

I don't know if something in lattice has changed, but that doesn't look as
though it should work:  the code to do the plot was never evaluated.  I
think you would need eval=TRUE in the first chunk, or
ortho-xyplot1-code
ahead of the plot command in the second.



Yes. I notice that it was me who introduced the eval=FALSE (I'm not
sure why). Hopefully that should fix it.

However, there _has_ been a recent lattice update, where the internals
have undergone some change, so there is a chance that is to blame. I
won't be able to take a look before day after tomorrow.

-Deepayan
  



--
Michael Friendly Email: frien...@yorku.ca 
Professor, Psychology Dept.

York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Streethttp://datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
R-help@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.


[R] Sweave: infelicities with lattice graphics

2010-07-15 Thread Michael Friendly
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.

-Michael

--
Michael Friendly Email: friendly AT yorku DOT ca 
Professor, Psychology Dept.

York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
R-help@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.


Re: [R] Sweave: infelicities with lattice graphics

2010-07-15 Thread Duncan Murdoch

On 15/07/2010 4:51 PM, Michael Friendly 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.


If the lattice call is always last in the chunk, I believe this would 
work as a replacement for the second chunk:


ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6=
ortho-xyplot1-code
print(.Last.value)
@

and then you'll only have to edit the first one.  But I haven't tried 
this, so something might go wrong...


Duncan Murdoch

__
R-help@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.


Re: [R] Sweave: infelicities with lattice graphics

2010-07-15 Thread Claudia Beleites

Dear Michael,

I know this situation from writing vignettes and I usually cheat a bit

I redefine the functions along these lines:

plotmap - function (...) print (hyperSpec:::plotmap (...))

   (plotmap is a lattice-function for hyperSpec objects)

plotmap can tehn be used without the print in the vignettes - this works 
fine for almost all cases. Only, if you have a structure that one of the 
redefined functions call another one of them, you get e.g. a pdf with 2 
pages.


Have a look at the vignettes and particularly the file vignettes.defs 
of package hyperSpec 
(https://r-forge.r-project.org/scm/viewvc.php/Vignettes/?root=hyperspec).


BTW: I find it polite to mention that some definitions etc. are executed 
silently and where people can find it.


Cheers,

Claudia

__
R-help@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.


Re: [R] Sweave: infelicities with lattice graphics

2010-07-15 Thread carslaw

I have wondered about this too.  The approach I use isn't pretty but does
have a couple of advantages - there is only one set of code to run and I
have control over the figure size.  

The first part of the code below is what is shown in the document (but not
run), and the second part actually runs the code and makes the plot.

no2hist, eval=FALSE=
hist(mydata$no2)
no2hist1, echo = FALSE, results=hide=
pdf(no2hist.pdf)
no2hist
dev.off()
@
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{no2hist}
\caption{The caption.}
   \label{fig:hist}
\end{figure}

I'd be interested to know if there are neater ways of doing this.

Regards,

David
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Sweave-infelicities-with-lattice-graphics-tp2290665p2290677.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Sweave: infelicities with lattice graphics

2010-07-15 Thread Claudia Beleites

Dear David,

you can use Gin:

\setkeys{Gin}{width=0.5\linewidth}

just before the chunk that actually produces the figure.



and, cool, I hadn't realized, that

fig = TRUE, echo = FALSE=
print (
chunk-with-lattice-function
   )
@

works.

with {} inside the print there can be even more than one statement in 
the chunk-with-lattice-function.
However, that's not a good idea. There may be surprises due to the 
question how often the chunk-with-lattice-function is actually executed.


Claudia


I have wondered about this too.  The approach I use isn't pretty but does
have a couple of advantages - there is only one set of code to run and I
have control over the figure size.

The first part of the code below is what is shown in the document (but not
run), and the second part actually runs the code and makes the plot.

no2hist, eval=FALSE=
hist(mydata$no2)
no2hist1, echo = FALSE, results=hide=
pdf(no2hist.pdf)
no2hist
dev.off()
@
\begin{figure}
 \centering
 \includegraphics[width=0.5\textwidth]{no2hist}
 \caption{The caption.}
\label{fig:hist}
\end{figure}

I'd be interested to know if there are neater ways of doing this.

Regards,

David


__
R-help@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.


Re: [R] Sweave: infelicities with lattice graphics

2010-07-15 Thread Deepayan Sarkar
On Thu, Jul 15, 2010 at 1:51 PM, Michael Friendly frien...@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@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.