This function converts 'neuron', 'mesh3d', or 'neuronlist' objects, which represent 3D points linked by lines in space, into data frames that describe paths compatible with ggplot2's geom_path, or geom_polygon for mesh3d objects. Neuron objects are fundamental data structures in the natverse ecosystem for representing neuronal morphology (see Jefferis et al., 2007; and https://natverse.org/nat/articles/neurons-intro.html).
Usage
ggplot2_neuron_path(x, rotation_matrix = NULL, ...)
# S3 method for class 'neuron'
ggplot2_neuron_path(x, rotation_matrix = NULL, ...)
# S3 method for class 'neuronlist'
ggplot2_neuron_path(x, rotation_matrix = NULL, ...)
# S3 method for class 'mesh3d'
ggplot2_neuron_path(x, rotation_matrix = NULL, ...)
# S3 method for class '`NULL`'
ggplot2_neuron_path(x, rotation_matrix = NULL, ...)
Value
A data frame with columns X, Y, Z, and group, where each group represents a continuous path in the neuron or a polygon in the mesh.
See also
rgl_view
for a way to obtain rotation_matrix
Examples
if (FALSE) { # \dontrun{
library(nat.ggplot)
# Convert a single neuron to ggplot2-compatible format
neuron_data <- ggplot2_neuron_path(banc.skels[[1]])
head(neuron_data)
# Plot with gganat base
gganat +
geom_path(data = neuron_data,
aes(x = X, y = Y, group = group))
# Apply rotation matrix
neuron_rotated <- ggplot2_neuron_path(banc.skels[[1]],
rotation_matrix = banc_view)
# Convert neuronlist
neuronlist_data <- ggplot2_neuron_path(banc.skels)
# Convert mesh3d object
mesh_data <- ggplot2_neuron_path(banc.brain_neuropil)
} # }