交互式工作(rkward)的 ggplot2 代码在 Lyx/pgfSweave 下崩溃 - 请提示!
我在 *.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') (谢谢一辉!)
代码
- 粘贴到rkward的R命令窗口中可以正常工作。
- 在 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
- 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我必须承认,这又是我的直接错误(间接的可能是 Sweave 的错)。我对 R 中未记录的“
空图形设备
”过于大胆和乐观,Cameron 被我误导了:http://yihui.name/en/2010/12/a-special-graphics-device-in -r-the-null-device/
虽然这个空设备可以稍微加快 Sweave 速度并避免产生不必要的图形文件,但它似乎无法处理所有图形系统。当我编写该解决方案时,我没有仔细测试 ggplot2(即网格图形)。
目前,您可以将其放在 Sweave 文档的第一个代码块中:
这将显示一个冗余的 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).For the time being, you can put this in the first code chunk of your Sweave document:
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.