ggseg3d - creating interactive brain segmentation plots with plotly

ggseg3d - creating interactive brain segmentation plots with plotly

Table of Content

Discover how to create interactive 3D brain atlas plots using the ggseg3d package in R. Learn to visualize neuroimaging data with plotly, including setting up and customizing brain atlas plots. Ideal for neuroscientists and data scientists working with brain segmentation data.

Looking through my blogposts, I realised I’ve never written about my colleague Didac and my package for 3d mesh plots of brain atlases using plotly. I’ve already showed some functionality from out {ggseg}-package, in the introductory blogpost and follow-up on animating it.

I guess it’s extra timely to do it now, as we recently split the mesh-plot function off the main {ggseg}-package and into it’s own package, and also did some re-writing of core-functionality of the package. Like the {ggseg}-package, {ggseg3d} is made to plot brain atlas data. In Neuroimaging, it is quite common to use these pre-defined areas of the brain, defined through functional or structural qualitites. Since the brain has three dimensions, we thought it would be neat to actually have a plot where you would actually look at the brain at all angles, and also be able to interact with it.

So started my long and arduous search for tri-surface mesh plots, and plotly became the obvious candidate. I had little to no experience with plotly, or with mesh-plots, so it was a real struggle. But I’m happy I stuck with it, and managed to make a tool that I now am really proud of. There are still lots of things to improve, but I believe the core-funcitonality is in place now, and everything else is a bonus!

Get 3d-plotting

{ggseg3d} can be installed from our works github account, using remotes

remotes::install_github("LCBC-UiO/ggseg3d")

And off the bat, it should be fairly easy to use, or atleast make the first plot.

library(ggseg3d)
ggseg3d()

It plots the right hemisphere of the dkt_3d dataset, which is the Desikan-Killany atlas, a Freesurfer default. You can easily interact with the plot, turn it, pan it, swivel it. Have at it, have fun!

The function takes several arguments:

.data	
A data.frame to use for plot aesthetics. Must include a column called "area" corresponding to areas.

atlas	
Either a string with the name of a 3d atlas to use.

surface	
String. Which surface to plot. Either "pial","white", or "inflated"[default]

hemisphere	
String. Hemisphere to plot. Either "left" or "right"[default], can also be "subcort".

label	
String. Quoted name of column in atlas/data that should be used to name traces

text	
String. Quoated name of column in atlas/data that should be added as extra information in the hover text.

colour	
String. Quoted name of column from which colour should be supplied

palette	
String. Either name of paletteer palette or vector of hex colours, used if colour is numeric.

na.colour	
String. Either name, hex of RGB for colour of NA in colour.

na.alpha	
Numeric. A number between 0 and 1 to control transparency of NA-regions.

show.legend	
Logical. Toggle legend if colour is numeric.

  • Aug 30, 2018

    Introducing the ggseg R-package for brain segmentations

    Discover ggseg, an R package designed for plotting brain segmentations directly in R with ggplot2. Learn how to visualize results from different brain atlases, customize plots, and integrate your own data. Ideal for neuroimaging researchers needing to plot segmented brain data efficiently.

    Read
    plots
    packages
    neuroimaging
    r
  • Oct 01, 2018

    Get the brain animated!

    Explore how to create animated visualizations of brain data using the ggseg and gganimate packages in R. Learn to prepare data for animations, customize plots, and generate smooth transitions to visualize changes across different conditions such as age.

    Read
    packages
    neuroimaging
    r
  • May 25, 2018

    Circular plots in R and adding images

    Read
    plots
    neuroimaging
    r
  • Nov 16, 2019

    Plotting GAMM interactions with ggplot2

    Discover how to visualize Generalized Additive Mixed Models (GAMMs) with interactions in R using ggplot2 and mgcv. This tutorial covers numeric and factor interactions, creating prediction datasets, and generating smooth plots. Ideal for enhancing your data analysis and visualization skills.

    Read
    r
    gamm
  • Jul 17, 2019

    R for Psychologists - part II

    Improve your data visualization skills in R with this comprehensive guide on creating plots using ggplot2. Learn to wrangle data, create long-format datasets, and produce various types of plots, including histograms, scatter plots, and regression lines. Ideal for psychologists transitioning from SPSS to R.