R语言画图-Error in get(getOption("device"))
来源:互联网 发布:业务流程数据化的例子 编辑:程序博客网 时间:2024/06/08 17:29
环境为:
R 3.3.1, Rscript 3.3.1 64位
windows 7 64位
当运行如下示例程序画loglog图:
## Create a data frame with artificial data.d.f <- data.frame( x = 1:100, y = 1:100 )## Open a new default device.get( getOption( "device" ) )()## Plot the data, hiding the points for now to prevent the calls to## abline() from drawing over the points.plot( y ~ x, data = d.f, type = "n", log = "xy", main = "Log-log Plot" )## Put grid lines on the plot, using a light blue color ("lightsteelblue2").abline( h = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] )abline( v = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] )## Draw the points over the grid lines.points( y ~ x, data = d.f )## Redraw the plot box over the grid lines.box()
1 . 在RGui中的R Console中运行情况:
报错: Error in get(getOption("device")) : invalid first argument
但是成功打开device并画图。
> ## Create a data frame with artificial data.> > d.f <- data.frame( x = 1:100, y = 1:100 )> > ## Open a new default device.> > get( getOption( "device" ) )()Error in get(getOption("device")) : invalid first argument> > ## Plot the data, hiding the points for now to prevent the calls to> ## abline() from drawing over the points.> > plot( y ~ x, data = d.f, type = "n", log = "xy", main = "Log-log Plot" )> > ## Put grid lines on the plot, using a light blue color ("lightsteelblue2").> > abline( h = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] )> abline( v = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] )> > ## Draw the points over the grid lines.> > points( y ~ x, data = d.f )> > ## Redraw the plot box over the grid lines.> > box()
2 . 在 RStudio
(Version 0.99.903)中,get( getOption( "device" ) )()
返回
NULL
,并成功画图,单独运行该语句依然返回NULL
但是能成功打开device
> ## Create a data frame with artificial data.> > d.f <- data.frame( x = 1:100, y = 1:100 )> > ## Open a new default device.> > get( getOption( "device" ) )()NULL> > ## Plot the data, hiding the points for now to prevent the calls to> ## abline() from drawing over the points.> > plot( y ~ x, data = d.f, type = "n", log = "xy", main = "Log-log Plot" )> > ## Put grid lines on the plot, using a light blue color ("lightsteelblue2").> > abline( h = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] )> abline( v = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] )> > ## Draw the points over the grid lines.> > points( y ~ x, data = d.f )> > ## Redraw the plot box over the grid lines.> > box()> >
3 . 将示例代码存入脚本文件,在windows 7 x64 cmd
中使用 Rscript
运行脚本文件,报错:
Error in get(getOption("device")) :
不输出结果文件。
Mac OS X 10.9.4中用Rscript
运行脚本报错为:
Error in get(getOption("device")) : invalid first argumentExecution halted
同样不输出结果文件。
解决方法:
针对Rscript
和 RConsole
将 get(getOption("device"))
改为 dev.new()
RConsole
不再报错,Rscript
运行脚本正常默认输出pdf文件也不报错
参照:
[1] http://r.789695.n4.nabble.com/R-2-8-0-get-platform-device-with-get-getOption-quot-device-quot-td920607.html
The “device” option can now be a function, and is one in some standard setups. Consequentially, get(getOption(“device”)) will fail; programmers should usually use dev.new() instead.
[2] https://stat.ethz.ch/pipermail/r-devel/2008-April/049319.html
2.7.0 provides a function dev.new()
.
As from R 2.5.0, options(“device”) can be a character string or a function. If the latter, this construct does not work.
[3] R in Action, Second Edition. Robert I. Kabacoff. May 2015. ISBN 9781617291388. 608 pages. printed in black & white.
First, you can open a new graph window before creating a new graph:
dev.new()
statements to create graph 1
dev.new()
statements to create a graph 2
etc.
Each new graph will appear in the most recently opened window.
- R语言画图-Error in get(getOption("device"))
- R语言学习-问题解决-reached getOption("max.print")
- R语言基础画图
- R语言画图
- R语言学习--画图
- R语言基本画图
- R语言ggplot2画图
- R语言画图入门
- R语言基础画图
- R语言︱画图
- r语言 画图 参数
- R语言基础画图
- R语言画图
- R语言画图
- R语言画图
- R 语言画图的基本参数
- R语言-画图(上)
- R语言-画图(下)
- R判断逻辑回归参数共线性
- 【51 Nod1378】夹克老爷的愤怒
- JavaEE Spring框架学习笔记(理论学习之通过@Autowired 自动装配注解的使用)
- Struts2文件下载
- 【51nod1403】 有趣的堆栈
- R语言画图-Error in get(getOption("device"))
- leetcode : Add Two Numbers
- 文章标题
- 数值分解
- 项目实战篇-餐馆管理系统—MFC,PHP,MySql:3.MFC端Person类及个人信息修改
- Android自定义简易照相机
- JS 10进制转其他进制
- mysql设置字符,不能启动的解决办法和注意事项
- 摸爬滚打DirectX11_day06——材质与顶点法线