2013-05-03 92 views
24

我有一个使用RGL的3D图。我想用颜色突出显示某些变量的分布情况来制作相同的图。要做到这一点,我想有相同的情节,我如何找到并设置情节的方向?保存RGL绘图的方向plot3d()plot

一旦我做了一个初步情节,我会移动它以找到一个很好的显示角度,我想保存该角度并将其合并到未来的绘图脚本中。任何人都有关于如何做到这一点的建议?

library(rgl) 
plot3d(iris) 
#play with the plot to find a good angle 
#save the angle for future plots 
+9

尝试'pp < - par3d(no.readonly = TRUE); ...; par3d(pp)' – 2013-05-03 15:24:38

+1

也有 - 有一个很好的方法来硬编码它 - 我,保存'pp'作为一个变量,我可以将它合并到未来的脚本,无需重新计算? – zach 2013-05-03 15:30:24

+0

也检查'?rgl.viewpoint' – James 2013-05-03 16:05:08

回答

21

本的评论基本上回答你的问题;这只适用于他写的expand.dots;)

## In an inital session: 

library(rgl) 
plot3d(iris) 

## Now move the image around to an orientation you like 

## Save RGL parameters to a list object 
pp <- par3d(no.readonly=TRUE) 

## Save the list to a text file 
dput(pp, file="irisView.R", control = "all") 

....... 

## Then, in a later session, to recreate the plot just as you had it: 

library(rgl) 
pp <- dget("irisView.R") 
plot3d(iris) 
par3d(pp) 
+1

在'dput()'行中使用'control =“all”'更安全,因为它保存了所有的解析信息并确保了dget的结果。 – 2014-04-23 17:31:40

+0

没有'control =“all”'我得到一个错误*不正确的维数*,因为dget()不正确地将userMatrix展平为一个列表。 – 2014-04-23 17:32:36

+0

@AssadEbrahim - 感谢您的注意!我刚刚编辑了答案并纳入了您的建议改进。 – 2014-04-23 17:35:09