Whenever I do a re-plot on a RGL plot3D it causes the view orientation of the plot to be reset to it's default.
Does anyone know how to save these settings so that I can reapply them after a plot is redrawn. I tried this:
# save settings
pp <- par3d(no.readonly=TRUE)
# initialize plot
plot3d(c(), c(), c(), "", "", "")
# Replot data here
# ...
# restore settings
par3d(pp)
However, this did not restore the plot orientation.
EDIT: printing out the result of par3d() shows that the values are not getting updated as the plot is rotated and zoomed, so I'm guessing this is the issue. It might be an issue only with ShinyRGL if people have gotten it to work with rgl.
The problem with the rgl plot is that it does not change the par3d
rotation matrix as you rotate the plot (same for zoom). Additionally, I can't find any documentation that hints to where the rotation/zoom state is stored. Thus, we have no information on the current state of the plot, and saving/loading that state is impossible.
My solution is to use sliders to manually control the rotation/zoom of the plot; and when those sliders change, we manually update the par3d
rotation matrix.
While I really don't like this solution because it takes away a lot of the convenience of plot rotation/zoom, it's the only way I was able to maintain the rotation/zoom state after updates.
par3d
par3d
contains the rotation/zoom state.I don't know whether this changed in recent rgl versions, but for me it is working. I am using rgl version 0.95.1441.
Define a function that loads data and calls plot3d()
(here it uses random data):
library(rgl)
newRGLrandom <- function(){
n <- 10
x <- sort(rnorm(n))
y <- rnorm(n)
z <- rnorm(n) + atan2(x, y)
plot3d(x, y, z, col = rainbow(n), size=10)
}
The plot starts in the standard orientation:
newRGLrandom()
Then I rotate it by hand in the rgl window:
When I call the newRGLrandom()
function again it shows the new plot in the same rotation:
newRGLrandom()
I am also able to save the user rotation:
uM <- par3d()$userMatrix
and move the plot to the stored rotation later on:
par3d(userMatrix = uM)
Saving the whole par3d
also works for me:
pp <- par3d(no.readonly=TRUE)
par3d(pp)
I don't know why it didn't work when you tried it. Maybe it is OS specific?
My sessionInfo()
is the following:
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
locale:
[1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgl_0.95.1441
loaded via a namespace (and not attached):
[1] tools_3.2.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With