问题
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