ggplot2 code that works interactively (rkward) crashes under Lyx/pgfSweave - Hints please!
I encounter the following error in the *.Rnw.log:
Error: chunk 3 (label=printgraph)
Error in grid.Call.graphics("L_text", as.graphicsAnnot(x$label), x$x, :
Metric information not available for this family/device
only in Lyx and depending upon the statement
+ scale_y_log10(ylim=c(0.025,5))
in the following sample code:
<<Code, tidy=T, sanitize=TRUE>>=
require(ggplot2)
df.qdf=data.frame(T = c(0 ,1,2 ,0 ,1.5,2.5)
,q.500 = c(0.025,2,1 ,0.025, 4,2 )
,q.025 = 0.5*c(0.025,2,1 开发者_运维百科,0.025, 4,2 )
,q.975 = 1.5*c(0.025,2,1 ,0.025, 4,2 )
,Occasion = c( 1,1,1 ,2 , 2,2 )
)
theme_set(theme_bw())
Graph=(qplot(T,q.500,data=df.qdf)
+geom_smooth(aes(ymin=q.025,ymax=q.975)
,data=df.qdf
,stat='identity'
,fill='blue')
+ylab('Response')
+xlab('Time [h]')
+facet_grid(facet=.~Occasion)
) +scale_y_log10(ylim=c(0.025,5))
@
<<printgraph,echo=FALSE,fig=TRUE,width=10,height=7,sanitize=TRUE>>=
print(Graph)
@
under
- openSUSE 11.2,
- TeXlive2010, (update all installed as of today),
- R version 2.12.1 (2010-12-16) svn rev 53855 (x86_64-unknown-linux-gnu) with update.packages() as of today,
- LyX 1.6.8 (reconfigured after TeXLive update),
- pgfSweave of 18 December 2010 as configured according to Yihui Xie's script ('http://gitorious.org/yihui/lyx-sweave/blobs/raw/master/lyx-sweave-config.R') (Thank you Yihui!)
The code works ok
- when pasted in the R-command window of rkward.
- in lyx when I comment out the
+scale_y_log10(ylim=c(0.025,5))
I have tried already
sanitize=TRUE
options(device = function(...) { .Call("R_GD_nullDevice", PACKAGE = "grDevices") })
and
dev.off()
(suggested in http://www.inside-r.org/questions/problems-ggplot-and-pgfsweave)
None of this helps. Please!
I must confess that this is directly my fault again (indirectly it might be Sweave to blame). I was too bold and optimistic on the undocumented ``null graphics device
'' in R, and Cameron was mislead by me:
http://yihui.name/en/2010/12/a-special-graphics-device-in-r-the-null-device/
Although this null device can speed up Sweave a little bit and avoid producing unnecessary graphics files, it seems to be unable to handle all graphics systems. When I wrote that solution, I did not test carefully on ggplot2
(i.e. grid graphics).
> .Call("R_GD_nullDevice", PACKAGE = "grDevices") NULL > print(Graph) Error in grid.Call.graphics("L_text", as.graphicsAnnot(x$label), x$x, : Metric information not available for this family/device > dev.off() null device 1
For the time being, you can put this in the first code chunk of your Sweave document:
options(device = pdf)
This will bring up a redundant PDF file (Rplots.pdf
), but can solve your problem anyway.
I will discuss with pgfSweave authors or Sweave authors later. This seems to be easy to improve in Sweave, but the problem has been there for many years.
精彩评论