Captures the current viewing parameters from an active rgl window and returns
them in a format suitable for use as a rotation matrix with nat.ggplot functions.
This allows users to interactively find their desired viewing angle using
plot3d()
and then apply the same view to ggplot2 visualisations.
Value
A list containing:
- userMatrix
A 4x4 rotation matrix that can be used with the
rotation_matrix
parameter in nat.ggplot functions- zoom
The current zoom level
- windowRect
The window dimensions
Details
The typical workflow is:
Plot neurons or brain meshes using
plot3d()
from the nat packageInteractively rotate the view using the mouse to find the desired angle
Call
rgl_view()
to capture the current view parametersUse the
$userMatrix
component as therotation_matrix
argument in nat.ggplot functions likegeom_neuron()
orggneuron()
Examples
if (FALSE) { # \dontrun{
library(nat)
library(nat.ggplot)
library(ggplot2)
# First, plot neurons in 3D and rotate to desired view
plot3d(banc.brain_neuropil, alpha = 0.3)
plot3d(banc.skels)
# Capture the view after rotating with mouse
my_view <- rgl_view()
# Use the captured view in ggplot2
ggplot() +
geom_neuron(banc.brain_neuropil,
rotation_matrix = my_view$userMatrix,
cols = c("grey75", "grey50"),
alpha = 0.3) +
geom_neuron(banc.skels,
rotation_matrix = my_view$userMatrix)
} # }