Exporting rgl.snapshot and rgl.postscript fails

為{幸葍}努か 提交于 2019-12-07 23:12:09

问题


I am currently using the rgl package for some data representation. Here's my command

mypath("directory")
png(file=mypath, res=600, width=10.5, height= 10.5,units="in",bg = "transparent")
require(rgl)
set.seed(1)
df <- data.frame(replicate(4,sample(1:200,1000,rep=TRUE)))
colnames(df) <- c("var1","var2","var3","var4")
plot3d(x=df$var1, y=df$var2, z=df$var3, col=as.numeric(df$var4), size=0.5, type='s',xlab="var1",ylab="var2",zlab="var3")
rgl.snapshot(mypath)

The command above works and produces a tiny image, which I wasn't able to make bigger, or increase its resolution (to 600).

I have also tried to export a pdf using:

rgl.postscript(mypath, fmt="pdf") 

but when I execute the command R goes into a "not responding" state.

Can somebody please show me how to properly export the file? I would prefer the have the PNG with the resolution 600 dpi.

Cheers,


回答1:


A solution can be to set the size of the window using open3d() :

require(rgl)
set.seed(1)

df <- data.frame(replicate(4,sample(1:200,1000,rep=TRUE)))
colnames(df) <- c("var1","var2","var3","var4")
open3d(windowRect=c(100,100,700,700))
plot3d(x=df$var1, y=df$var2, z=df$var3, col=as.numeric(df$var4), size=0.5, type='s',xlab="var1",ylab="var2",zlab="var3")
rgl.snapshot(<path to png file>)



回答2:


May be someone need. I used the following combination for persp3Drgl:

persp3Drgl(...)
par3d( windowRect=c( 0,0,100,100 ) )
snapshot3d( file.path(plotDir, "3D.png"), top = TRUE )

Without top = TRUE it got failed.



来源:https://stackoverflow.com/questions/23242846/exporting-rgl-snapshot-and-rgl-postscript-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!