Skip to contents

The stat-first spelling of geom_brain(). Both build the same layer – a StatBrain that aggregates and joins your data onto the atlas geometry, drawn by geom. Reach for stat_brain() when you want to pair StatBrain with a different geom (e.g. a custom polygon geom); otherwise geom_brain() is the friendlier entry point.

Usage

stat_brain(
  mapping = aes(),
  data = NULL,
  atlas,
  hemi = NULL,
  view = NULL,
  position = position_brain(),
  context = TRUE,
  fun = mean,
  geom = GeomBrain,
  show.legend = NA,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by ggplot2::aes().

data

A data.frame containing variables to map. If NULL, the atlas is plotted without user data. Add a facet with ggplot2::facet_wrap() to draw one brain per group.

atlas

A ggseg_atlas object (e.g. dk(), aseg(), tracula()).

hemi

Character vector of hemispheres to include (e.g. "left", "right"). Defaults to all hemispheres in the atlas.

view

Character vector of views to include, as recorded in the atlas data. For cortical atlases: "lateral", "medial". For subcortical/tract atlases: slice identifiers like "axial_3". Defaults to all views.

position

Position adjustment, either as a string or the result of a call to position_brain().

context

Keep the rest of the brain as a soft grey backdrop (TRUE, the default), or show only the regions you're plotting (FALSE).

fun

Function used to combine multiple data rows that map to the same atlas region, applied within each facet panel. Defaults to mean(). Any function reducing a vector to a single value works (e.g. median(), max()).

geom

The geometric object used to render the atlas. Defaults to GeomBrain.

show.legend

Logical. Should this layer be included in the legends?

inherit.aes

Logical. If FALSE, overrides the default aesthetics rather than combining with them.

...

Additional arguments passed to ggplot2::geom_polygon().

Value

A list of ggplot2 layer and coord objects.

See also

Examples

library(ggplot2)

# Equivalent to geom_brain(atlas = dk())
ggplot() +
  stat_brain(atlas = dk())