交互式工作(rkward)的 ggplot2 代码在 Lyx/pgfSweave 下崩溃 - 请提示!

发布于 2024-10-12 05:20:28 字数 2037 浏览 4 评论 0原文

我在 *.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 

仅在 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 rev 53855 (x86_64-unknown-linux-gnu) with update.packages() 截至今天,
  • LyX 1.6.8(TeXLive 更新后重新配置),
  • 2010 年 12 月 18 日的 pgfSweave 根据 Yihui Xie 的脚本配置 ('http://gitorious.org/yihui/lyx-sweave/blobs/raw/master/lyx-sweave-config.R') (谢谢一辉!)

代码

  1. 粘贴到rkward的R命令窗口中可以正常工作。
  2. 在 lyx 中,当我注释掉 +scale_y_log10(ylim=c(0.025,5))

我已经尝试过

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

并且

dev.off() 

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

这些都没有帮助。 请!

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

  1. when pasted in the R-command window of rkward.
  2. 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如何视而不见 2024-10-19 05:20:28

我必须承认,这又是我的直接错误(间接的可能是 Sweave 的错)。我对 R 中未记录的“空图形设备”过于大胆和乐观,Cameron 被我误导了:

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 中似乎很容易改进,但问题已经存在很多年了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文