2013-05-03 41 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