Skip to contents

Matches your data to a brain atlas by a shared column (usually region), keeping every atlas region whether or not you have a value for it. Grouped data (via dplyr::group_by()) gives one complete atlas per group. You rarely need this directly – geom_brain() joins your data for you; reach for brain_join() when you want the joined sf object yourself.

Usage

brain_join(data, atlas, by = NULL)

Arguments

data

A data.frame with a column matching an atlas column (typically "region"). Can be grouped with dplyr::group_by().

atlas

A ggseg_atlas object or data.frame containing atlas data.

by

Character vector of column names to join by. If NULL (default), columns are detected automatically.

Value

An sf object if the atlas contains geometry, otherwise a tibble.

Examples

someData <- data.frame(
  region = ggseg.formats::atlas_regions(dk())[1:4],
  p = sample(seq(0, .5, .001), 4),
  stringsAsFactors = FALSE
)

brain_join(someData, dk())
#> Merging atlas and data by region.
#> Simple feature collection with 191 features and 9 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 84.2049 ymin: 0 xmax: 5359.689 ymax: 429.9372
#> CRS:           NA
#> First 10 features:
#>                         label     view  hemi                            region
#> 1                  lh_unknown  lateral  left                              <NA>
#> 2                  lh_unknown   medial  left                              <NA>
#> 3                  lh_unknown inferior  left                              <NA>
#> 4                  rh_unknown  lateral right                              <NA>
#> 5                  rh_unknown   medial right                              <NA>
#> 6                  rh_unknown inferior right                              <NA>
#> 7                 lh_bankssts  lateral  left banks of superior temporal sulcus
#> 8                 lh_bankssts superior  left banks of superior temporal sulcus
#> 9                 lh_bankssts inferior  left banks of superior temporal sulcus
#> 10 lh_caudalanteriorcingulate   medial  left         caudal anterior cingulate
#>         lobe atlas     type  colour     p                       geometry
#> 1       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((926.5936 60...
#> 2       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((1782.84 18....
#> 3       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((367.1256 13...
#> 4       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((3849.766 60...
#> 5       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((4318.844 20...
#> 6       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((3190.519 5....
#> 7   temporal    dk cortical #196428 0.172 MULTIPOLYGON (((1121.478 12...
#> 8   temporal    dk cortical #196428 0.172 MULTIPOLYGON (((2448.464 20...
#> 9   temporal    dk cortical #196428 0.172 MULTIPOLYGON (((534.4782 21...
#> 10 cingulate    dk cortical #7D64A0 0.406 MULTIPOLYGON (((1921.971 20...
brain_join(someData, dk(), "region")
#> Simple feature collection with 191 features and 9 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 84.2049 ymin: 0 xmax: 5359.689 ymax: 429.9372
#> CRS:           NA
#> First 10 features:
#>                         label     view  hemi                            region
#> 1                  lh_unknown  lateral  left                              <NA>
#> 2                  lh_unknown   medial  left                              <NA>
#> 3                  lh_unknown inferior  left                              <NA>
#> 4                  rh_unknown  lateral right                              <NA>
#> 5                  rh_unknown   medial right                              <NA>
#> 6                  rh_unknown inferior right                              <NA>
#> 7                 lh_bankssts  lateral  left banks of superior temporal sulcus
#> 8                 lh_bankssts superior  left banks of superior temporal sulcus
#> 9                 lh_bankssts inferior  left banks of superior temporal sulcus
#> 10 lh_caudalanteriorcingulate   medial  left         caudal anterior cingulate
#>         lobe atlas     type  colour     p                       geometry
#> 1       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((926.5936 60...
#> 2       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((1782.84 18....
#> 3       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((367.1256 13...
#> 4       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((3849.766 60...
#> 5       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((4318.844 20...
#> 6       <NA>    dk cortical    <NA>    NA MULTIPOLYGON (((3190.519 5....
#> 7   temporal    dk cortical #196428 0.172 MULTIPOLYGON (((1121.478 12...
#> 8   temporal    dk cortical #196428 0.172 MULTIPOLYGON (((2448.464 20...
#> 9   temporal    dk cortical #196428 0.172 MULTIPOLYGON (((534.4782 21...
#> 10 cingulate    dk cortical #7D64A0 0.406 MULTIPOLYGON (((1921.971 20...