2011-01-14 45 views
1

我遇到以下错误在* .Rnw.log:交互式工作(rkward)ggplot2代码在Lyx/pgfSweave下崩溃 - 请提示!

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 

只有在LYX并根据声明

+ scale_y_log10(ylim=c(0.025,5)) 
在下面的示例代码

<<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) 
@ 

  • 的openSUSE 11.2,
  • TeXlive2010,(更新所有已安装截至今日)
  • [R版本2.12.1(2010-12-16)SVN修订版53855(x86_64的未知-Linux的GNU)与update.packages( )截至今日,
  • LyX的1.6.8(更新的texlive)后重新配置,
  • 2010年12月18 pgfSweave作为根据艺辉谢的剧本 ('http://gitorious.org/yihui/lyx-sweave配置/blobs/raw/master/lyx-sweave-config.R') (谢谢Yihui!)

代码正常工作

  1. 当粘贴在rkward的R-命令窗口。
  2. 时,我注释掉+scale_y_log10(ylim=c(0.025,5))

LYX我曾尝试已经

sanitize=TRUE 
options(device = function(...) {  .Call("R_GD_nullDevice", PACKAGE = "grDevices") }) 

dev.off() 

(在http://www.inside-r.org/questions/problems-ggplot-and-pgfsweave建议)

没有这种帮助。 请!

回答

4

我必须承认,这是我的错误(间接可能是Sweave责备)。我太大胆和乐观在R上的无证``null graphics device“”,卡梅伦被我误导:

http://yihui.name/en/2010/12/a-special-graphics-device-in-r-the-null-device/

虽然这个空设备可以加快Sweave一点点,避免产生不必要的图形文件,它似乎无法处理所有图形系统。当我写这个解决方案时,我没有仔细测试ggplot2(即网格图形)。

> .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 

暂时,你可以把这个在您的Sweave文档的第一个代码块:

options(device = pdf)

这将带来一个冗余PDF文件(Rplots.pdf),但可以解决你的问题无论如何。

我会在稍后与pgfSweave作者或Sweave作者讨论。 Sweave似乎很容易改善,但问题多年以来一直存在。

+1

不要觉得太糟糕,关于网格图形的细节可能会非常棘手。直到最近,`tikzDevice`才以稳定的方式处理ggplot2的字符串长度计算。那是在“我以为我修好了”很多次之后。 – Sharpie 2011-01-16 20:20:50