Title: | Plotting Tool for Brain Atlases |
---|---|
Description: | Contains 'ggplot2' geom for plotting brain atlases using simple features. The largest component of the package is the data for the two built-in atlases. Mowinckel & Vidal-Piñeiro (2020) <doi:10.1177/2515245920928009>. |
Authors: | Athanasia Mo Mowinckel [aut, cre] , Didac Vidal-Piñeiro [aut] , Ramiro Magno [aut] |
Maintainer: | Athanasia Mo Mowinckel <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.6.6 |
Built: | 2024-11-20 03:51:46 UTC |
Source: | https://github.com/ggseg/ggseg |
adapt_scales
returns a list of coordinate breaks and labels
for axes or axes label manipulation of the ggseg brain atlases.
adapt_scales(geobrain, position = "dispersed", aesthetics = "labs")
adapt_scales(geobrain, position = "dispersed", aesthetics = "labs")
geobrain |
a data.frame containing atlas information. |
position |
String choosing how to view the data. Either "dispersed"[default] or "stacked". |
aesthetics |
String of which aesthetics to adapt scale of, either "x","y", or "labs". |
nested list with coordinates for labels
Coerce object into an object of class 'brain_atlas'.
as_brain_atlas(x)
as_brain_atlas(x)
x |
object to make into a brain_atlas |
an object of class 'brain_atlas'.
Create ggseg atlas
as_ggseg_atlas(x) ## Default S3 method: as_ggseg_atlas(x) ## S3 method for class 'data.frame' as_ggseg_atlas(x) ## S3 method for class 'ggseg_atlas' as_ggseg_atlas(x) ## S3 method for class 'brain_atlas' as_ggseg_atlas(x)
as_ggseg_atlas(x) ## Default S3 method: as_ggseg_atlas(x) ## S3 method for class 'data.frame' as_ggseg_atlas(x) ## S3 method for class 'ggseg_atlas' as_ggseg_atlas(x) ## S3 method for class 'brain_atlas' as_ggseg_atlas(x)
x |
object to make into a ggseg_atlas |
Object of class 'ggseg_atlas'
Coordinate data for the subcortical parcellations implemented in Freesurfer.
data(aseg)
data(aseg)
An object of class brain_atlas
of length 4.
An object of class 'brain_atlas' for plotting with ggseg
Fischl et al., (2002). Neuron, 33:341-355 (PubMed)
Other ggseg_atlases:
dk
data(aseg)
data(aseg)
Creates an object of class 'brain_atlas' that is compatible for plotting using the ggseg-package plot functions
brain_atlas(atlas, type, data, palette = NULL)
brain_atlas(atlas, type, data, palette = NULL)
atlas |
atlas short name, length one |
type |
atlas type, cortical or subcortical, length one |
data |
data.frame with atlas data |
palette |
named character vector of colours |
an object of class 'brain_atlas' containing information
on atlas name, type, data and palette. To be used in plotting
with geom_brain
.
Joins data frame with a brain-atlas object.
brain_join(data, atlas, by = NULL)
brain_join(data, atlas, by = NULL)
data |
data.frame |
atlas |
atlas data |
by |
optional character vector of column to join by |
either an sf-object (if brain atlas) or a tibble (if ggseg-atlas) with merged atlas and data
someData = data.frame( region = c("transverse temporal", "insula", "precentral","superior parietal"), p = sample(seq(0,.5,.001), 4), stringsAsFactors = FALSE) brain_join(someData, dk) brain_join(someData, dk, "region")
someData = data.frame( region = c("transverse temporal", "insula", "precentral","superior parietal"), p = sample(seq(0,.5,.001), 4), stringsAsFactors = FALSE) brain_join(someData, dk) brain_join(someData, dk, "region")
Convenience function to extract names of
brain labels from a brain_atlas
.
Brain labels are usually default naming obtained
from the original atlas data.
brain_labels(x) ## S3 method for class 'ggseg_atlas' brain_labels(x) ## S3 method for class 'brain_atlas' brain_labels(x)
brain_labels(x) ## S3 method for class 'ggseg_atlas' brain_labels(x) ## S3 method for class 'brain_atlas' brain_labels(x)
x |
brain atlas |
Character vector of atlas region labels
brain_pal
return HEX colours for the different ggseg atlases.
brain_pal(name, n = "all", direction = 1, unname = FALSE, package = "ggseg")
brain_pal(name, n = "all", direction = 1, unname = FALSE, package = "ggseg")
name |
String name of atlas |
n |
Number of colours to return (or "all" [default]) |
direction |
Direction of HEX, -1 reverses order Necessary if applying palette to other data than the brain atlas it comes from. |
unname |
return unnamed vector (default = FALSE) |
package |
package to get brain_pals data from (ggseg or ggsegExtra) |
vector of colours
brain_pal("dk") brain_pal("aseg")
brain_pal("dk") brain_pal("aseg")
Get info on brain palettes
brain_pals_info(package = "ggseg")
brain_pals_info(package = "ggseg")
package |
package to get brain_pals data from (ggseg or ggsegExtra) |
data.frame with palette information
brain_pals_info()
brain_pals_info()
Convenience function to extract names of
brain regions from a brain_atlas
brain_regions(x) ## S3 method for class 'ggseg_atlas' brain_regions(x) ## S3 method for class 'brain_atlas' brain_regions(x) ## S3 method for class 'data.frame' brain_regions(x)
brain_regions(x) ## S3 method for class 'ggseg_atlas' brain_regions(x) ## S3 method for class 'brain_atlas' brain_regions(x) ## S3 method for class 'data.frame' brain_regions(x)
x |
brain atlas |
Character vector of brain region names
Coordinate data for the Desikan-Killiany Cortical atlas, with 40 regions in on the cortical surface of the brain.
data(dk)
data(dk)
An object of class brain_atlas
of length 4.
An object of class 'brain_atlas' for plotting with ggseg
Fischl et al. (2004) Cerebral Cortex 14:11-22 (PubMed)
Other ggseg_atlases:
aseg
data(dk)
data(dk)
call to geom_sf
geom_brain( mapping = aes(), data = NULL, atlas, hemi = NULL, side = NULL, position = position_brain(), show.legend = NA, inherit.aes = TRUE, ... )
geom_brain( mapping = aes(), data = NULL, atlas, hemi = NULL, side = NULL, position = position_brain(), show.legend = NA, inherit.aes = TRUE, ... )
mapping |
argument to pass to |
data |
data.frame with data to plot |
atlas |
object of type brain_atlas to plot |
hemi |
hemisphere to plot. Defaults to everything in the atlas. |
side |
slice to plot, as recorded in the "side" column in the atlas data. Defaults to all. |
position |
position of the data. Default is "identity" but can be
changed by |
show.legend |
logical. Should legend be added or not. |
inherit.aes |
logical. if aes should be inherited from the main ggplot call or not |
... |
arguments to |
ggplot object
library(ggplot2) ggplot() + geom_brain(atlas = dk)
library(ggplot2) ggplot() + geom_brain(atlas = dk)
The 'ggseg_atlas' class is a subclass of ['data.frame'][data.frame()], created in order to have different default behaviour. It heavily relies on the "tibble" ['tbl_df'][tibble()]. [tidyverse](https://www.tidyverse.org/packages/), including [dplyr](http://dplyr.tidyverse.org/), [ggplot2](http://ggplot2.tidyverse.org/), [tidyr](http://tidyr.tidyverse.org/), and [readr](http://readr.tidyverse.org/).
ggseg_atlas(x)
ggseg_atlas(x)
x |
data.frame to be made a ggseg-atlas |
a tibble with polygon coordinates for plotting brain regions
Objects of class 'ggseg_atlas' have: * A 'class' attribute of 'c("ggseg_atlas", "tbl_df", "tbl", "data.frame")'. * A base type of '"list"', where each element of the list has the same [NROW()]. * A lot of this script and its functions are taken from the ['tibble'][tibble()]-package
Validate brain atlas
is_brain_atlas(x)
is_brain_atlas(x)
x |
an object |
logical if object is of class 'brain_atlas'
Validate ggseg_atlas
is_ggseg_atlas(x)
is_ggseg_atlas(x)
x |
an object |
logical if object is of class 'ggseg_atlas'
Function to be used in the position argument in geom_brain to alter the position of the brain slice/views.
position_brain(position = "horizontal")
position_brain(position = "horizontal")
position |
formula describing the rows ~ columns organisation. |
a ggproto object
library(ggplot2) ggplot() + geom_brain(atlas = dk, aes(fill = region), position = position_brain(. ~ side + hemi ), show.legend = FALSE) ggplot() + geom_brain(atlas = dk, aes(fill = region), position = position_brain(side ~ hemi ), show.legend = FALSE)
library(ggplot2) ggplot() + geom_brain(atlas = dk, aes(fill = region), position = position_brain(. ~ side + hemi ), show.legend = FALSE) ggplot() + geom_brain(atlas = dk, aes(fill = region), position = position_brain(side ~ hemi ), show.legend = FALSE)
Recursively reads in all stats files for an atlas (given a unique character string), for all subjects in the subjects directory. Will add hemisphere and subject id to the data.
read_atlas_files(subjects_dir, atlas)
read_atlas_files(subjects_dir, atlas)
subjects_dir |
FreeSurfer subject directory |
atlas |
unique character combination identifying the atlas |
tibble with stats information for subjects from FreeSurfer
## Not run: subj_dir <- "/path/to/freesurfer/7.2.0/subjects/" read_atlas_files(subj_dir, "aseg.stats") read_atlas_files(subj_dir, "lh.aparc.stats") ## End(Not run)
## Not run: subj_dir <- "/path/to/freesurfer/7.2.0/subjects/" read_atlas_files(subj_dir, "aseg.stats") read_atlas_files(subj_dir, "lh.aparc.stats") ## End(Not run)
FreeSurfer atlas stats files have a format that can be difficult to easily read in to R. This function takes a raw stats-file from the subjects directory and reads it in as a data.frame.
read_freesurfer_stats(path, rename = TRUE)
read_freesurfer_stats(path, rename = TRUE)
path |
path to stats file |
rename |
logical. rename headers for ggseg compatibility |
tibble with stats information for subjects from FreeSurfer
## Not run: subj_dir <- "/path/to/freesurfer/7.2.0/subjects/" aseg_stats <- file.path(subj_dir, "bert/stats/aseg.stats") read_freesurfer_stats(aseg_stats) ## End(Not run)
## Not run: subj_dir <- "/path/to/freesurfer/7.2.0/subjects/" aseg_stats <- file.path(subj_dir, "bert/stats/aseg.stats") read_freesurfer_stats(aseg_stats) ## End(Not run)
FreeSurfer has functions to create
tables from raw stats files. If you have
data already merged using the aparcstats2table
or asegstats2table
from FreeSurfer,
this function will read in the data and prepare it
for ggseg.
read_freesurfer_table(path, measure = NULL, ...)
read_freesurfer_table(path, measure = NULL, ...)
path |
path to the table file |
measure |
which measure is the table of |
... |
additional arguments to |
tibble with stats information for subjects from FreeSurfer
## Not run: file_path <- "all_subj_aseg.txt" read_freesurfer_table(file_path) ## End(Not run)
## Not run: file_path <- "all_subj_aseg.txt" read_freesurfer_table(file_path) ## End(Not run)
Function for repositioning pre-joined atlas data (i.e. data and atlas already joined to a single data frame). This makes it possible for users to reposition the geometry data for the atlas for control over final plot layout. For even more detailed control over the positioning, the "hemi" and "side" columns should be converted into factors and ordered by wanted order of appearance.
reposition_brain(data, position = "horizontal")
reposition_brain(data, position = "horizontal")
data |
sf-data.frame of joined brain atlas and data |
position |
position formula for slices |
sf-data.frame with repositioned slices
reposition_brain(dk, hemi ~ side) reposition_brain(dk, side ~ hemi) reposition_brain(dk, hemi + side ~ .) reposition_brain(dk, . ~ hemi + side)
reposition_brain(dk, hemi ~ side) reposition_brain(dk, side ~ hemi) reposition_brain(dk, hemi + side ~ .) reposition_brain(dk, . ~ hemi + side)
The 'brain' palette scales provides scales for the different atlases in the package. Colours are according to the colours used in the papers where the atlases where first introduced.
scale_brain( name = "dk", na.value = "grey", ..., aesthetics = c("fill", "colour", "color") ) scale_colour_brain(...) scale_color_brain(...) scale_fill_brain(...)
scale_brain( name = "dk", na.value = "grey", ..., aesthetics = c("fill", "colour", "color") ) scale_colour_brain(...) scale_color_brain(...) scale_fill_brain(...)
name |
String name of atlas |
na.value |
String name or hex for the colour of NA entries |
... |
additional arguments to pass to |
aesthetics |
String vector of which aesthetics to scale c("colour", "color", "fill"). |
scaling function for altering colour of ggplot aesthetics
The following palettes are available for use with these scales:
dk, aseg
tracula, jhu, yeo7, yeo17, glasser, chenAr, chenTh,
scale_brain() scale_colour_brain() scale_fill_brain()
scale_brain() scale_colour_brain() scale_fill_brain()
The 'brain' palette scales provides scales for the different atlases in the package. Colours are according to the colours used in the papers where the atlases where first introduced.
scale_brain2( palette, na.value = "grey", ..., aesthetics = c("fill", "colour", "color") ) scale_colour_brain2(...) scale_color_brain2(...) scale_fill_brain2(...)
scale_brain2( palette, na.value = "grey", ..., aesthetics = c("fill", "colour", "color") ) scale_colour_brain2(...) scale_color_brain2(...) scale_fill_brain2(...)
palette |
named character vector of regions and colours |
na.value |
String name or hex for the colour of NA entries |
... |
additional arguments to pass to |
aesthetics |
String vector of which aesthetics to scale c("colour", "color", "fill"). |
scaling function for altering colour of ggplot aesthetics
The following palettes are available for use with these scales:
dk, aseg
tracula, jhu, yeo7, yeo17, glasser, chenAr, chenTh,
scale_brain() scale_colour_brain() scale_fill_brain()
scale_brain() scale_colour_brain() scale_fill_brain()
The 'brain' axis and label scales provides scales for the different atlases in the package. These add axis labels and tick labels corresponding to the different atlases.
scale_continous_brain( atlas = dk, position = "dispersed", aesthetics = c("y", "x") ) scale_x_brain(...) scale_y_brain(...) scale_labs_brain(atlas = dk, position = "dispersed", aesthetics = "labs")
scale_continous_brain( atlas = dk, position = "dispersed", aesthetics = c("y", "x") ) scale_x_brain(...) scale_y_brain(...) scale_labs_brain(atlas = dk, position = "dispersed", aesthetics = "labs")
atlas |
data.frame containing the atlas |
position |
Character of either "dispersed" or "stacked". |
aesthetics |
String vector of which aesthetics to scale "x", "y", or "labs". |
... |
additional arguments to pass to |
a scaling function to alter continuous axes labels in ggplot2
## Not run: scale_x_brain() scale_y_brain() scale_labs_brain() ## End(Not run)
## Not run: scale_x_brain() scale_y_brain() scale_labs_brain() ## End(Not run)
a set of themes created for the ggseg plots. Use theme() to tweak.
theme_brain(text.size = 12, text.family = "mono") theme_darkbrain(text.size = 12, text.family = "mono") theme_custombrain( plot.background = "white", text.colour = "darkgrey", text.size = 12, text.family = "mono" ) theme_brain2( plot.background = "white", text.colour = "darkgrey", text.size = 12, text.family = "mono" )
theme_brain(text.size = 12, text.family = "mono") theme_darkbrain(text.size = 12, text.family = "mono") theme_custombrain( plot.background = "white", text.colour = "darkgrey", text.size = 12, text.family = "mono" ) theme_brain2( plot.background = "white", text.colour = "darkgrey", text.size = 12, text.family = "mono" )
text.size |
Specify size of plot text |
text.family |
Specify font family |
plot.background |
Specify fill of plot background ('theme_custombrain' only) |
text.colour |
Specify colour of plot text |
Default theme for ggseg. Transparent background, no axis lines, and no grid.
Dark equivalent to theme_brain, with black background, and light text.
Theme for easy customisation of the brain themes.
function that alters the themeing of a ggplot object
Athanasia Mo Mowinckel
[ggplot()], [aes()], [geom_polygon()], [coord_fixed()] from the ggplot2 package
library(ggplot2) p <- ggplot() + geom_brain(atlas = dk) p + theme_brain() p + theme_darkbrain()
library(ggplot2) p <- ggplot() + geom_brain(atlas = dk) p + theme_brain() p + theme_darkbrain()