【问题标题】:Save the orientation of a RGL plot3d() plot保存 RGL plot3d() 绘图的方向
【发布时间】:2013-05-03 15:22:11
【问题描述】:

我有一个使用 RGL 的 3D 绘图。我想使用颜色制作相同的图来突出某些变量的分布。为此,我想拥有相同的绘图,如何找到并设置绘图的方向?

完成初步绘图后,我会四处移动它以找到一个不错的显示角度,我想保存该角度并将其合并到未来的绘图脚本中。有人对如何执行此操作有建议吗?

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

【问题讨论】:

  • 试试pp <- par3d(no.readonly=TRUE); ...; par3d(pp)
  • 还有 - 有没有一种硬编码的好方法 - 即,将 pp 保存为一个变量,我可以将其合并到未来的脚本中而无需重新计算?
  • 也可以查看?rgl.viewpoint
  • 谢谢詹姆斯。我可以想象使用 rgl.viewpoint 获取 par3D() 调用的输出并将视图硬编码到我的脚本中 - 很棒的提示。

标签: r rgl


【解决方案1】:

Ben 的评论基本上回答了您的问题;这只是将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)

【讨论】:

  • dput() 行中使用control="all" 更安全,因为这样可以保存所有的解析信息并确保dget 的结果有效。
  • 没有control="all" 我得到一个错误incorrect number of dimensions,因为 dget() 错误地将 userMatrix 展平为一个列表。
  • @AssadEbrahim -- 感谢您的注意!我刚刚编辑了答案,并结合了您建议的改进。
猜你喜欢
  • 2015-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-08
相关资源
最近更新 更多