Skip to contents

This function creates a ggplot2 geom layer for visualising neuron objects. It supports 'neuron', 'neuronlist', and 'mesh3d' objects. For split neurons (created using flow centrality analysis from Schneider-Mizell et al., 2016), it colours axonal and dendritic compartments differently.

Usage

geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class 'neuron'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class 'neuronlist'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class 'mesh3d'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class 'hxsurf'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class '`NULL`'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class 'list'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class 'matrix'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class 'data.frame'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class 'dotprops'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class 'synapticneuron'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

# S3 method for class 'splitneuron'
geom_neuron(
  x = NULL,
  rotation_matrix = NULL,
  root = 3,
  size = 0.5,
  cols = c("navy", "turquoise"),
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  threshold = Inf,
  ...
)

Arguments

x

A 'neuron', 'neuronlist', or 'mesh3d' object to be visualised.

rotation_matrix

An optional 4x4 rotation matrix to apply to the neuron coordinates.

root

Numeric, if >0 and x is or contains neuron objects, then the root node is plotted as a dot of size root. If FALSE or 0 no root node is plotted.

size

Numeric, the line width for neuron skeleton paths. Default is 0.5.

cols

The colour to plot the neurons in. If length(cols)==length(x) each neuron will be coloured by its index in x applied to cols.

stat

The statistical transformation to use on the data for this layer.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

threshold

the minimum threshold for healing neuron skeletons for visualisation, using nat::stitch_neurons_mst.

...

Other arguments passed on to layer().

Value

A list of ggplot2 geom layers for visualising the neuron.

Examples

if (FALSE) { # \dontrun{
library(nat.ggplot)

# Plot a single neuron
gganat +
  geom_neuron(banc.skels[[1]], rotation_matrix = banc_view)

# Plot all neurons with custom colours
gganat +
  geom_neuron(banc.skels,
              rotation_matrix = banc_view,
              cols = c("purple", "magenta"))

# Plot brain mesh as context
gganat +
  geom_neuron(banc.brain_neuropil,
              rotation_matrix = banc_view,
              cols = c("grey75", "grey50"),
              alpha = 0.3)

# Plot split neurons showing axon/dendrite
gganat +
  geom_neuron(banc.neurons.flow[[1]],
              rotation_matrix = banc_view)

# Plot synapses as points
gganat +
  geom_neuron(as.matrix(banc.syns[, c("X", "Y", "Z")]),
              rotation_matrix = banc_view,
              root = 0.5,
              cols = c("navy", "red"))
} # }