ggseg3d - creating interactive brain segmentation plots with plotly

ggseg3d - creating interactive brain segmentation plots with plotly

Table of Content

ggseg3d is a package for 3d mesh plots of brain atlases using plotly . It is made to plot brain atlas data . It should be fairly easy to use or atlele to make the first plot . It can be installed from our works GitHub account using remotes .

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

    The ggseg R-package for brain segmentations is intended for those who need to easily plot results or overviews of segmentet data . The package is developed as part of our lab [The Center for Lifespanism and Cognition [LCBC-UiO]

    Read
    plots
    packages
    neuroimaging
    r
  • Oct 01, 2018

    Get the brain animated!

    The ggseg package was so well received that we almost immediately got it on [Neuroconductor]. We got some pull requests from people helping us improve the code, and particularly get it ready for CRAN when we decide to submit it there . The package vignettes are update on how you may supply data for facetting .

    Read
    packages
    neuroimaging
    r
  • May 25, 2018

    Circular plots in R and adding images

    Circular plots are becoming more and more popular in for visualising associatetions between different phenomena . I think they look pretty cool, and while I have not yet published a paper with it, I did prep a lot of scripts for plotting my analysis results with it .

    Read
    plots
    neuroimaging
    r
  • Nov 16, 2019

    Plotting GAMM interactions with ggplot2

    Plotting GAMM interactions with ggplot2 is not always easy, especially if you have some interactions in there . Plotting the results of GAMMs are not always so easy . I’ll be using the diamonds dataset for this, as it has some nice non-linear features .

    Read
    r
    gamm
  • Jul 17, 2019

    R for Psychologists - part II

    R for Psychologists - part III: Getting SPSS data into R, doing some data wrangling (altering the data), plotting, and running a simple linear model . Part II: Plotting in R through ggplot2 really is a way to understand how to organise and alter data in R to suit your needs .