nat: NeuroAnatomy Toolbox

DOI Build Status Coverage Status

An R package for the (3D) visualisation and analysis of biological image data, especially tracings of single neurons. See nat.examples and frulhns for sample code.

nat is a cleaned up version of code that has been used in a number of papers from our group including:

Cell 2007 Cover CB 2010 Cover Nature 2011 Cell 2013 Abstract

Quick Start

For the impatient ...

# install
# use

# plot some test data (?kcs20 for details)
# Drosophila Kenyon cells processed from raw data at
plot3d(kcs20, col=type)
# get help

A larger data set, 300 olfactory projection neurons from Grosjean et al 2011:


# 3d plot of neurons from olfactory glomeruli beginning DM
# coloured by glomerulus
rval=plot3d(MyNeurons, subset=grepl("^DM",Glomerulus), col=factor(Glomerulus),
  lwd=2, WithNodes=FALSE)
# make a legend so that you know which colours match which glomerulus
with(attr(rval,'df'), legend('center', legend = unique(Glomerulus), fill=unique(col)))

# more help



nat is an R package and therefore runs on Mac/Linux/Windows. The only pre-requisite for most functionality is a recent version of R (>=3.1.0 recommended).

3D visualisation is provided by the rgl package based on OpenGL. On Mac OS X you must have a copy of XQuartz, the X11 window manager, installed. This is no longer a default install since Mac OS X 10.8, but the OS should offer to it install it for you if something tries to use it. Alternatively you can get it directly from

If you want to apply non-rigid registrations calculated by the Computational Morphometry Toolkit (CMTK) you will need to install that separately – see section External Dependencies below.


As of v1.0 there is a released version on CRAN. This is normally updated only every few months.


If you wish to run the package tests, it is necessary to install with all dependencies:

install.packages("nat", dependencies=TRUE)

Development version

nat remains under quite active development, so you may wish to install the development version directly from github. The recommended way to do this is to install Hadley Wickham's invaluable devtools package (if you have not already done so) and then use that to install nat.

# install devtools if required
if (!require("devtools")) install.packages("devtools")
# then install nat

The nat package includes extensive unit tests which are run along with R's (extremely fastidious) package check routines by the Travis continuous integration server. The master branch is therefore considered very stable. However, you can install the latest point release version as follows:


if you want to have the latest confirmed stable version. The same syntax can be used to install any arbitrary version that you want from github. See ?install_github for details.

Note: Windows users need Rtools to install in this way, but devtools should offer to install this for you if you do not already have it.

External Dependencies

nat is self sufficient for core functionality, but the transformation of 3D data using Computational Morphometry Toolkit (CMTK) registrations depends on an external installation of that toolkit. CMTK binaries can be downloaded for Windows, Linux and Mac at Source code is available from the same site or an unofficial mirror repository at We have extensive experience of using CMTK under Linux (where we compile from source) and Mac (where we compile or use the MacOSX-10.6-x86_64.dmg binary installers). We have also used neurodebian to install as part of the Travis continuous integration setup (see the project's .travis.yml file).