Learn R Programming

ggseg

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. Plotting results of analyses on regions or networks often involves swapping between statistical tools, like R, and software for brain imaging to correctly visualise analysis results.

This package aims to make it possible to plot results directly through R.

Atlases

There are currently four atlases available in the package:

  1. dk - Desikan-Killiany atlas (aparc).
  2. aseg - Automatic subcortical segmentation.

Note: As of version 1.5.3, ggseg was split into two packages: one for 2d polygon plots in ggplot, and another for 3d mesh plots through plotly. This was done to reduce package size, dependencies, and also to simplify maintenance. If you want the 3d plotting tool, please go the ggseg3d repository.

You may find more atlases and functions to create new atlases in the companion package ggsegExtra.

Installation

The package can be installed from CRAN.

install.packages("ggseg")

Alternatively, ggseg may also be installed through its ggseg r-universe:

# Enable this universe
options(repos = c(
    ggseg = 'https://ggseg.r-universe.dev',
    CRAN = 'https://cloud.r-project.org'))

# Install some packages
install.packages('ggseg')

The development version of the package can be installed using devtools.

install.packages("remotes")
remotes::install_github("ggseg/ggseg")

The functions are now installed, and you may load them when you want to use them. All functions are documented in standard R fashion.

Use

library(ggseg)
library(ggplot2)
plot(dk)

plot(aseg)

While default atlas plots will give you an idea of how the atlases look, you will likely want to project your own data onto the plot.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
someData <- tibble(
  region = rep(c("transverse temporal", "insula",
           "precentral","superior parietal"), 2), 
  p = sample(seq(0,.5,.001), 8),
  groups = c(rep("g1", 4), rep("g2", 4))
)

someData %>%
  group_by(groups) %>%
  ggplot() +
  geom_brain(atlas = dk, 
             position = position_brain(hemi ~ side),
             aes(fill = p)) +
  facet_wrap(~groups)
#> merging atlas and data by 'region'

The package also has several vignettes, to help you get started using it. You can access it here

You can also see one of the creators blog for introductions to its use here

Report bugs or requests

Don’t hesitate to ask for support using github issues, or requesting new atlases. While we would love getting help in creating new atlases, you may also request atlases through the issues, and we will try to get to it.

Funding

This tool is partly funded by:

EU Horizon 2020 Grant: Healthy minds 0-100 years: Optimising the use of European brain imaging cohorts (Lifebrain).

Grant agreement number: 732592.

Call: Societal challenges: Health, demographic change and well-being

Copy Link

Version

Install

install.packages('ggseg')

Monthly Downloads

1,466

Version

1.6.7

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Athanasia Mo Mowinckel

Last Published

November 14th, 2025

Functions in ggseg (1.6.7)

dk

Desikan-Killiany Cortical Atlas
ggseg_atlas

`ggseg_atlas` class
ggseg

ggseg: Plot brain segmentations with ggplot
read_freesurfer_table

Read in stats table from FreeSurfer
scale_continous_brain

Axis and label scales from the ggseg atlases
read_freesurfer_stats

Read in raw FreeSurfer stats file
scale_brain2

Colour and fill scales from the ggseg atlases
geom_brain

Brain geom
reposition_brain

Reposition brain slices
scale_brain

Colour and fill scales from the ggseg atlases
brain_labels

Extract unique labels of brain regions
adapt_scales

Scale ggseg plot axes.
as_ggseg_atlas

Create ggseg atlas
position_brain

Alter brain atlas position
brain_pal

Generate palettes from the ggseg atlases
aseg

Freesurfer automatic subcortical segmentation of a brain volume
read_atlas_files

Read in atlas data from all subjects
brain_regions

Extract unique names of brain regions
brain_pals_info

Get info on brain palettes
as_brain_atlas

Create brain atlas
brain_join

Join atlas and data
brain_atlas

Constructor for brain atlas
is_ggseg_atlas

Validate ggseg_atlas
is_brain_atlas

Validate brain atlas
theme_brain

ggseg plot theme