Skip to contents

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.

Usage

rgl_view()

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:

  1. Plot neurons or brain meshes using plot3d() from the nat package

  2. Interactively rotate the view using the mouse to find the desired angle

  3. Call rgl_view() to capture the current view parameters

  4. Use the $userMatrix component as the rotation_matrix argument in nat.ggplot functions like geom_neuron() or ggneuron()

See also

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)
} # }