-
Notifications
You must be signed in to change notification settings - Fork 1
Plotting brain images with ggseg
Vlad Drobinin edited this page Jul 7, 2021
·
1 revision
-
ggesg
package details for creating brain figures right in R - More info available in the publication: Visualization of Brain Statistics With R Packages ggseg and ggseg3d
- Our reproducible example script for plotting structural images in R
- works on the output of running all models on dk atlas, example found in this private repository
- the code below helps clean the significant model output into a data frame compatible with
ggseg
- cleans strings for ggseg
- prepare hemisphere column
ggseg_df <- sig_models %>%
select(brain_var, estimate, statistic, p.value) %>%
# scale estimate for plotting
mutate(beta = scale(estimate)) %>%
# remove freesurfer prefix
mutate_at("brain_var", str_remove, "fs_") %>%
# remove gray vol suffix
mutate_at("brain_var", str_remove, "_grayvol") %>%
# create hemisphere variable based on string
mutate(hemi = case_when(
grepl("^l_", brain_var) ~ "left",
grepl("^r_", brain_var) ~ "right",
TRUE ~ "both/other"
)) %>%
# clean up l and r string
mutate(brain_var = str_remove(brain_var, "l_")) %>%
mutate(brain_var = str_remove(brain_var, "r_"))
- manual rename of brain vars in order to work with ggseg
- there might be built-in solutions for this in package vignettes
ggseg_dat <- ggseg_df %>%
mutate(region = case_when(
brain_var == "bankssts" ~ "bankssts",
brain_var == "caudalanteriorcingulate" ~ "caudal anterior cingulate",
brain_var == "caudalmiddlefrontal" ~ "caudal middle frontal",
# brain_var == "corpus callosum",
brain_var == "cuneus" ~ "cuneus",
brain_var == "entorhinal" ~ "entorhinal",
brain_var == "frontalpole" ~ "frontal pole",
brain_var == "fusiform" ~ "fusiform",
brain_var == "inferiorparietal" ~ "inferior parietal",
brain_var == "inferiortemporal" ~ "inferior temporal",
brain_var == "insula" ~ "insula",
brain_var == "isthmuscingulate" ~ "isthmus cingulate",
brain_var == "lateraloccipital" ~ "lateral occipital",
brain_var == "lateralorbitofrontal" ~ "lateral orbitofrontal",
brain_var == "lingual" ~ "lingual",
brain_var == "medialorbitofrontal" ~ "medial orbitofrontal",
brain_var == "middletemporal" ~ "middle temporal",
brain_var == "paracentral" ~ "paracentral",
brain_var == "parahippocampal" ~ "parahippocampal",
brain_var == "parsopercularis" ~ "pars opercularis",
brain_var == "parsorbitalis" ~ "pars orbitalis",
brain_var == "parstriangularis" ~ "pars triangularis",
brain_var == "pericalcarine" ~ "pericalcarine",
brain_var == "postcentral" ~ "postcentral",
brain_var == "posteriorcingulate" ~ "posterior cingulate",
brain_var == "precentral" ~ "precentral",
brain_var == "precuneus" ~ "precuneus",
brain_var == "rostralanteriorcingulate" ~ "rostral anterior cingulate",
brain_var == "rostralmiddlefrontal" ~ "rostral middle frontal",
brain_var == "superiorfrontal" ~ "superior frontal",
brain_var == "superiorparietal" ~ "superior parietal",
brain_var == "superiortemporal" ~ "superior temporal",
brain_var == "supramarginal" ~ "supramarginal",
brain_var == "temporalpole" ~ "temporal pole",
brain_var == "transversetemporal" ~ "transverse temporal"
))