class: middle, right, title-slide .title[ # Visualizing brain data ] .subtitle[ ## - the ggseg-suite of R-packages - ] .author[ ### Athanasia Monika Mowinckel ] .date[ ### 2023-12-01 ] --- background-image: url("https://drmowinckels.io/about/profile.png") background-position: right bottom background-size: auto 100% class: middle .pull-left[ ## Athanasia Monika Mowinckel [<i class="fa-brands fa-mastodon fa-2x" aria-hidden="true"></i> https://fosstodon.org/@Drmowinckels](https://fosstodon.org/@Drmowinckels) [<i class="fa-brands fa-github fa-2x" aria-hidden="true"></i> https://github.com/drmowinckels](https://github.com/drmowinckels) [<i class="fa-solid fa-globe fa-2x" aria-hidden="true"></i> https://drmowinckels.io/](https://drmowinckels.io/) - Staff scientist & RSE - PhD in cognitive psychology - Software Carpentry Instructor ] --- background-image: url(https://www.lifebrain.uio.no/vrtx/decorating/resources/images/logo.png), url(https://www.lifebrain.uio.no/web-banner_rev.jpg), url(https://www.lifebrain.uio.no/vrtx/decorating/resources/images/eu-flag.jpg) background-size: 50%, 100% auto, 10% background-position: 50% 10%, bottom center, 90% 10% --- layout: true <div class="my-sidebar"></div> --- class: dark, center, middle # Neuroimaging workflows --- background-image: url(https://fsl.fmrib.ox.ac.uk/fsl/wiki_static/fsl/img/fsl-logo-x2.png), url(https://freesurfer2016.sciencesconf.org/conference/freesurfer2016/pages/FSlogo.png), url(https://nipype.readthedocs.io/en/latest/_static/nipype-banner-bg.png), url(https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/98b0f6cf-f7e6-4051-b4f4-2aacf06f551b/a5cdc6ec-7ee3-4aaa-afbd-f283c68dd149/images/screenshot.png) background-size: 20%, 40%, 50%, 20% background-position: 20% 45%, 70% 45%, 85% 90%, 20% 95% ## MRI analyses are usually run in specialized software ??? - run in specialized software - but results and dissemination is usually run in stats software - switching between different software creates workflows that are hard to reproduce and keep track of --- background-image: url(https://visceralmind.files.wordpress.com/2017/04/voxel-brain.jpg?w=1024) background-size: contain ??? - the images are 3d matrices of 1mm cubic voxels, usually around 100 thousand voxels per brain - MRI analyses run large numbers of comparisons just within a single subjects' brain, and issues with multiple comparisons need to be dealt with --- background-image: url(https://www.researchgate.net/profile/Arno_Klein2/publication/233889622/figure/fig2/AS:271987822034957@1441858358467/Regions-in-the-DKT-cortical-labeling-protocol-Cortical-regions-of-interest-included-in.png) background-size: contain ??? - To reduce this problem, the brain is often reduced to a smaller set of functionally or structurally meaningful parcellations - here: the DK cortical atlas on an inflated brain (blown up like a balloon) to see also inside the grooves - measurements are extracted from these regions for metrics like coritcal thickness, surface area, gyrification index etc. and used in statistical models --- class: center, dark background-image: url(img/ggseg.png), url(img/ggseg3d.png), url(img/ggsegExtra.png) background-size: 15% background-position: 41% 43%, 59% 43%, 50% 77% # ggseg-suite -- .pull-left[ 2d polygons / geospatial ] -- .pull-left[ 3d mesh / tri-surface ] -- <br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br> atlas creation / installation --- class: middle, center, dark background-image: url(img/ggseg.png) background-size: 18% background-position: 50% 10% # ## Plotting 2d representations as polygons --- class: middle .pull-left[ ```r library(ggplot2, quietly = TRUE) library(ggseg, quietly = TRUE) plot(dk, show.legend = FALSE) ``` ] .pull-right[ <img src="index_files/figure-html/unnamed-chunk-1-1.png" width="100%" /> ] --- ## Using the core functionality .pull-left[ ```r ggplot() + geom_brain(atlas = dk, show.legend = FALSE) ``` ] .pull-right[ <img src="index_files/figure-html/unnamed-chunk-2-1.png" width="100%" /> ] --- ## Using the core functionality .pull-left[ **Position options* ```r ggplot() + geom_brain( atlas = dk, * position = position_brain( * hemi ~ side * ), show.legend = FALSE ) ``` ] .pull-right[ <img src="index_files/figure-html/unnamed-chunk-3-1.png" width="100%" /> ] --- ## Using your own data .pull-left[ ```r library(dplyr) someData <- tibble( region = rep(c("transverse temporal", "insula", "precentral", "superior parietal"),2), p = sample(seq(0,.5,.001), 8), Group = c(rep("G1",4), rep("G2",4))) ggplot(data = someData) + geom_brain( atlas = dk, position = position_brain(side ~ hemi), colour = "black", mapping = aes(fill = p)) ``` ] .pull-right[ ``` ## merging atlas and data by 'region' ``` <img src="index_files/figure-html/unnamed-chunk-4-1.png" width="100%" /> ] --- .pull-left[ ## Faceting groups ```r someData %>% * group_by(Group) %>% ggplot() + geom_brain( atlas = dk, position = position_brain(side ~ hemi), colour = "black", mapping = aes(fill = p) ) + * facet_wrap(~Group, * nrow = 2) ``` ] .pull-right[ ``` ## merging atlas and data by 'region' ``` <img src="index_files/figure-html/unnamed-chunk-5-1.png" width="100%" /> ] --- .pull-left[ ## Adapting the look ```r someData %>% group_by(Group) %>% ggplot() + geom_brain( atlas = dk, position = position_brain(side ~ hemi), colour = "black", mapping = aes(fill = p) ) + facet_wrap(~Group, nrow = 2) + theme(axis.text = element_blank(), axis.line = element_blank(), axis.ticks = element_blank(), axis.title = element_blank(), panel.background = element_blank() ) + scale_fill_viridis_c(na.value = "grey62") ``` ] .pull-right[ ``` ## merging atlas and data by 'region' ``` <img src="index_files/figure-html/unnamed-chunk-6-1.png" width="100%" /> ] --- class: middle .left-column[ ## Subcortical atlases ```r plot(aseg) ``` ] .right-column[ <img src="index_files/figure-html/unnamed-chunk-7-1.png" width="100%" /> ] --- class: middle, center, dark background-image: url(img/ggseg3d.png) background-size: 18% background-position: 50% 10% # ## Plotting 3d triangular meshes --- class: middle .pull-left[ ## Powered by plotly ### Fully interactive ```r library(ggseg3d) ggseg3d(atlas = dk_3d) ``` ] .pull-right[
] --- class: middle .pull-left[ ## subcortical structure ### with glass brain for reference ```r ggseg3d(atlas = aseg_3d) %>% add_glassbrain(hemisphere = "left") %>% remove_axes() ``` ] .pull-right[ <img src="aseg_3d.png" width="100%" /> ] --- class: middle, center, dark background-image: url(img/ggsegExtra.png) background-size: 18% background-position: 50% 10% # ## Creating and instaling atlases --- .pull-left[ # Many compatible atlases Can all be found in the ggseg r-universe https://ggseg.r-universe.dev/builds ```r library(ggsegExtra) repos <- ggseg_atlas_repos() ``` ``` ## opening url input connection. ``` ``` ## Found 27 records... Imported 27 records. Simplifying... ``` ``` ## closing url input connection. ``` ] .pull-right[ <table class="table" style="margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> Package </th> <th style="text-align:left;"> Version </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> ggsegYeo2011 </td> <td style="text-align:left;"> 1.0.2.002 </td> </tr> <tr> <td style="text-align:left;"> ggsegICBM </td> <td style="text-align:left;"> 1.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegSchaefer </td> <td style="text-align:left;"> 2.0.4 </td> </tr> <tr> <td style="text-align:left;"> ggsegChen </td> <td style="text-align:left;"> 1.0.01 </td> </tr> <tr> <td style="text-align:left;"> ggsegHO </td> <td style="text-align:left;"> 1.0.2.001 </td> </tr> <tr> <td style="text-align:left;"> ggsegKleist </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegArslan </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegFlechsig </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegEconomo </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegGlasser </td> <td style="text-align:left;"> 1.0.01 </td> </tr> <tr> <td style="text-align:left;"> ggsegAal </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegGordon </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegAicha </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegCampbell </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegIca </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegPower </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegBrodmann </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegBrainnetome </td> <td style="text-align:left;"> 0.0.1 </td> </tr> <tr> <td style="text-align:left;"> ggsegDesterieux </td> <td style="text-align:left;"> 1.0.1.002 </td> </tr> <tr> <td style="text-align:left;"> ggsegJHU </td> <td style="text-align:left;"> 1.0.1.001 </td> </tr> <tr> <td style="text-align:left;"> ggsegDefaultExtra </td> <td style="text-align:left;"> 1.0.01 </td> </tr> <tr> <td style="text-align:left;"> ggsegDKT </td> <td style="text-align:left;"> 1.0.1.001 </td> </tr> <tr> <td style="text-align:left;"> ggsegTracula </td> <td style="text-align:left;"> 1.0.1.001 </td> </tr> </tbody> </table> ] --- .pull-left[ ```r install_ggseg_atlas("LCBC-UiO/ggsegYeo2011") install_ggseg_atlas("LCBC-UiO/ggsegAal") ``` ```r library(ggsegYeo2011) library(ggsegAal) plot(yeo7, position = position_brain(hemi ~ side)) plot(aal, position = position_brain(hemi ~ side)) ``` ] .pull-right[ <img src="index_files/figure-html/yeo.out-1.png" width="100%" /><img src="index_files/figure-html/yeo.out-2.png" width="100%" /> ] --- class:dark, middle, center # Check out the online package docs Here you can find tutorials and more in-depth descriptions of what you can accomplish with the packages. ## [ggseg](https://lcbc-uio.github.io/ggseg/index.html) ## [ggseg3d](https://lcbc-uio.github.io/ggseg3d/index.html) ## [ggsegExtra](https://lcbc-uio.github.io/ggsegExtra/index.html) --- class: center, dark background-image: url(img/ggseg.png), url(img/ggseg3d.png), url(img/ggsegExtra.png) background-size: 15% background-position: 41% 43%, 59% 43%, 50% 77% # ggseg-suite .pull-left[ 2d polygons / geospatial ] .pull-left[ 3d mesh / tri-surface ] <br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br> atlas creation / installation --- class: title-slide, middle, right # Thanks to our lab # for funding to develop # these tools [oslobrains.no](https://www.oslobrains.no/)