library(ggsegExtra)
library(dplyr) # for cleaning the atlas data efficiently
library(tidyr) # for cleaning the atlas data efficiently
# The unique name of the atlas annot, without hemisphere in filename
annot_name <- "{GGSEG}"
# You might need to convert the annotation file
# convert atlas to fsaverage5
lapply(c("lh", "rh"),
function(x){
mri_surf2surf_rereg(subject = "fsaverage",
annot = annot_name,
hemi = x,
output_dir = here::here("data-raw/fsaverage5/"))
})
# Make 3d ----
{GGSEG}_3d <- make_aparc_2_3datlas(
annot = annot_name,
annot_dir = here::here("data-raw/fsaverage5/"),
output_dir = here::here("data-raw/")
)
ggseg3d(atlas = {GGSEG}_3d)
## fix atlas ----
# you might need to do some alteration of the atlas data,
# like cleaning up the region names so they do not contain
# hemisphere information, and any unknown region should be NA
{GGSEG}_n <- {GGSEG}_3d
{GGSEG}_n <- unnest({GGSEG}_n, ggseg_3d)
{GGSEG}_n <- mutate({GGSEG}_n,
region = gsub("_L$|_R$", "", region),
region = ifelse(grepl("Unknown|\\?", region, ignore.case = TRUE),
NA, region),
atlas = "{GGSEG}_3d"
)
{GGSEG}_3d <- as_ggseg3d_atlas({GGSEG}_n)
ggseg3d(atlas = {GGSEG}_3d)
# Make palette ----
brain_pals <- make_palette_ggseg({GGSEG}_3d)
usethis::use_data(brain_pals, internal = TRUE, overwrite = TRUE)
devtools::load_all(".")
# Make 2d polygon ----
{GGSEG} <- make_ggseg3d_2_ggseg({GGSEG}_3d, output_dir = here::here("data-raw/"))
plot({GGSEG})
{GGSEG} %>%
ggseg(atlas = ., show.legend = TRUE,
colour = "black",
mapping = aes(fill=region)) +
scale_fill_brain("{GGSEG}", package = "{REPO}", na.value = "black")
usethis::use_data({GGSEG}, {GGSEG}_3d,
internal = FALSE,
overwrite = TRUE,
compress="xz")
# make hex ----
atlas <- {GGSEG}
p <- ggseg(atlas = atlas,
hemi = "left",
view = "lateral",
show.legend = FALSE,
colour = "grey30",
size = .2,
mapping = aes(fill = region)) +
scale_fill_brain2(palette = atlas$palette) +
theme_void() +
hexSticker::theme_transparent()
lapply(c("png", "svg"), function(x){
hexSticker::sticker(p,
package = "{REPO}",
filename = sprintf("man/figures/logo.%s", x),
s_y = 1.2,
s_x = 1,
s_width = 1.5,
s_height = 1.5,
p_family = "mono",
p_size = 10,
p_color = "grey30",
p_y = .6,
h_fill = "white",
h_color = "grey30"
)
})
pkgdown::build_favicons(overwrite = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.