knitr::opts_chunk$set( collapse = TRUE, out.width = "100%", fig.width = 10 )
Using the ggseExtra package requires the two main ggseg-packages, containing the functions needed to plot the data. ggsegExtra is a meta-repository of data-sets that fit with the functions in those main packages, with functions to help you create your own custom atlases.
library(ggsegExtra)
Atlases are stored in their own online repositories. The list of repositories is periodically updated based on when we have confirmed a new atlas that works with the packages. These data-sets can be in our own github account (ggseg), and we are happy to add new repositories contributed by others here. To see all confirmed atlases:
ggseg_atlas_repos() # Search for repos with pattern ggseg_atlas_repos("Yeo") # Search is case-sensitive ggseg_atlas_repos("yeo") # Search is case-sensitive, but this can be fixed ggseg_atlas_repos("yeo", ignore.case = TRUE)
Installing atlases from the repos, we have convenience function, using the r-universe for all the ggseg packages
repo <- ggseg_atlas_repos("dkt", ignore.case = TRUE) if (!requireNamespace("ggsegDKT", quietly = TRUE)) { install_ggseg_atlas(repo$package) }
library(ggplot2) library(ggseg) ggplot() + geom_brain(atlas = ggsegDKT::dkt)
You should be able to easily switch the atlases, after loading ggsegExtra, so rather plot one of the ggsegExtra atlases directly to the function.
library(ggplot2) library(ggseg) # load on all atlases and palettes from the ggsegYeo2011 library library(ggsegDKT) ggplot() + geom_brain(atlas = dkt)
If you want to make sure it looks properly like the atlas you are after, or you want to plot an example of the original plot.
Most of the datasets also have corresponding palettes from the papers they were introduced from.
These colour-scales can be applied through the scale_X_brain
functions, and you must also specify which package the palette comes from.
ggplot() + geom_brain(atlas = dkt) + scale_fill_brain("dkt", package="ggsegDKT")
The same goes for ggseg3d, the new atlases, now available through the ggsegExtra package, can be plotted with the ggseg3d function and its helpers.
library(ggseg3d) ggseg3d(atlas = dkt_3d) %>% pan_camera("right lateral")
library(ggseg3d) library(plotly) p <- ggseg3d(atlas = dkt_3d) %>% pan_camera("right lateral") %>% plotly::add_annotations( text="Screen capture", legendtitle=TRUE, showarrow=FALSE, font = list(color = "#000000b4", family = 'sans serif', size = 50)) plotly::orca(p, "figures/vignette-dkt-3d-plot.png")
knitr::include_graphics("figures/vignette-dkt-3d-plot.png")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.