Closed alicarogojin closed 1 year ago
Hi!
Thanks for the question.
You'll need to make a data-frame where the colour2 column is a different hex colour for each of the regions you want in a different colour.
Below, I do so by making all regions mentioning the PFC in their region name green.
library(ggseg3d)
library(ggsegSchaefer)
library(dplyr)
regions3d <- c("7Networks_LH_Default_Temp_1","7Networks_LH_Default_Temp_2","7Networks_LH_Default_Temp_3"
,"7Networks_LH_Default_Temp_4","7Networks_LH_Default_Temp_5","7Networks_LH_Default_Par_1"
,"7Networks_LH_Default_Par_2","7Networks_LH_Default_Par_3","7Networks_LH_Default_Par_4"
,"7Networks_LH_Default_PFC_1","7Networks_LH_Default_PFC_2","7Networks_LH_Default_PFC_3"
,"7Networks_LH_Default_PFC_4","7Networks_LH_Default_PFC_5","7Networks_LH_Default_PFC_6"
,"7Networks_LH_Default_PFC_7","7Networks_LH_Default_PFC_8","7Networks_LH_Default_PFC_9"
,"7Networks_LH_Default_PFC_10","7Networks_LH_Default_PFC_11","7Networks_LH_Default_PFC_12"
,"7Networks_LH_Default_PFC_13","7Networks_LH_Default_pCunPCC_1","7Networks_LH_Default_pCunPCC_2"
,"7Networks_LH_Default_pCunPCC_3","7Networks_LH_Default_pCunPCC_4","7Networks_LH_Default_PHC_1")
data3d <- filter(schaefer7_200_3d$ggseg_3d[[1]],
region %in% regions3d) %>%
transmute(region, colour2 = if_else(grepl("PFC", region), "#00ff00", colour))
ggseg3d(data3d,
atlas = schaefer7_200_3d,
surface = "inflated",
hemisphere = "left",
colour = "colour2")
So you'll need to make sure your colour column is not a single static colour, but rather varies according to the scheme you want to use.
Thank you very much! This worked for me.
The problem I have now, is that I'm trying to do medial portions of PFC (PFC_2, 4, 6, 7,8, 10, 13) one colours and lateral PFC (PFC_1, 3, 5, 9, 11, 12) a different colour. However, when I use this part of the code
grepl("PFC_1", region), "#00ff00"
This in turn makes PFC_10, PFC_11, PFC_12, and PFC_13 all the same colour too since they contain "PFC_1" in them. Do you happen to know what could be a workaround for this, where I can manually control the colour for each of them?
Thank you again! Alica
Yes, this is using regular expression, which is a bit of a mess to learn, imo.
In this case, if you dont know regular expression, I would rather look for each region by name in a case_when
to capture each of them in turn.
Have a peak at the case_when documentation to learn about using it.
https://dplyr.tidyverse.org/reference/case_when.html
It would look something like:
data3d <- filter(schaefer7_200_3d$ggseg_3d[[1]],
region %in% regions3d) %>%
transmute(
region,
colour2 = case_when(
region %in% paste0("PFC_", c(1, 3, 5, 9, 11, 12)) ~ "#00ff00",
region %in% paste0("PFC_", c(2, 4, 6, 7, 8, 10, 13)) ~ "#ff0000"
)
Hi Dr. Mowinckel,
Thank you for your quick response! I've tried the full code below:
library(ggseg3d)
library(ggsegSchaefer)
library(dplyr)
regions3d <- c("7Networks_LH_Default_Temp_1","7Networks_LH_Default_Temp_2","7Networks_LH_Default_Temp_3"
,"7Networks_LH_Default_Temp_4","7Networks_LH_Default_Temp_5","7Networks_LH_Default_Par_1"
,"7Networks_LH_Default_Par_2","7Networks_LH_Default_Par_3","7Networks_LH_Default_Par_4"
,"7Networks_LH_Default_PFC_1","7Networks_LH_Default_PFC_2","7Networks_LH_Default_PFC_3"
,"7Networks_LH_Default_PFC_4","7Networks_LH_Default_PFC_5","7Networks_LH_Default_PFC_6"
,"7Networks_LH_Default_PFC_7","7Networks_LH_Default_PFC_8","7Networks_LH_Default_PFC_9"
,"7Networks_LH_Default_PFC_10","7Networks_LH_Default_PFC_11","7Networks_LH_Default_PFC_12"
,"7Networks_LH_Default_PFC_13","7Networks_LH_Default_pCunPCC_1","7Networks_LH_Default_pCunPCC_2"
,"7Networks_LH_Default_pCunPCC_3","7Networks_LH_Default_pCunPCC_4","7Networks_LH_Default_PHC_1")
data3d <- filter(schaefer7_200_3d$ggseg_3d[[1]],
region %in% regions3d) %>%
transmute(
region,
colour2 = case_when(
region %in% paste0("PFC_", c(1, 3, 5, 9, 11, 12)) ~ "#AD23AD",
region %in% paste0("PFC_", c(2, 4, 6, 7, 8, 10, 13)) ~ "#632AAD",
region %in% paste0("Temp_", c(1, 2, 3, 4, 5)) ~ "#1D8CAD",
region %in% paste0("Par_", c(1, 2, 3, 4)) ~ "#31AD88",
region %in% paste0("pCunPCC_", c(1, 2, 3)) ~ "#61AD03",
region %in% paste0("PHC_", c(1)) ~ "#FFA202"
))
ggseg3d(data3d,
atlas = schaefer7_200_3d,
surface = "inflated",
hemisphere = "left",
colour = "colour2") %>%
remove_axes()
However this returns a blank brain for me:
Sorry. This fell of my radar.
You likely found another solution but I'm posting anyway for others in the future.
You need to look at the dataframe you are making, if you have done so, you would have noticed that you have not successfully made a column of colours.
I used your code and the content of data3d
is:
# A tibble: 27 × 2
region colour2
<chr> <chr>
1 7Networks_LH_Default_Temp_1 NA
2 7Networks_LH_Default_Temp_2 NA
3 7Networks_LH_Default_Temp_3 NA
4 7Networks_LH_Default_Temp_4 NA
5 7Networks_LH_Default_Temp_5 NA
6 7Networks_LH_Default_Par_1 NA
7 7Networks_LH_Default_Par_2 NA
8 7Networks_LH_Default_Par_3 NA
9 7Networks_LH_Default_Par_4 NA
10 7Networks_LH_Default_PFC_1 NA
This is beacuse you are using %in%
to partially match in region names, which %in%
cannot do. TO use. %in%
you need to provide a vector with the full names of the regions you want to match.
The alternate route is to ude grepl
which you can use regular expression, but then you also have to alter your paste0
statement to collate (collapse) the various strings you want to match with the regexp OR character |
.
For me, this worked:
library(ggseg3d)
library(ggsegSchaefer)
library(dplyr)
regions3d <-
c(
"7Networks_LH_Default_Temp_1",
"7Networks_LH_Default_Temp_2",
"7Networks_LH_Default_Temp_3",
"7Networks_LH_Default_Temp_4",
"7Networks_LH_Default_Temp_5",
"7Networks_LH_Default_Par_1",
"7Networks_LH_Default_Par_2",
"7Networks_LH_Default_Par_3",
"7Networks_LH_Default_Par_4",
"7Networks_LH_Default_PFC_1",
"7Networks_LH_Default_PFC_2",
"7Networks_LH_Default_PFC_3",
"7Networks_LH_Default_PFC_4",
"7Networks_LH_Default_PFC_5",
"7Networks_LH_Default_PFC_6",
"7Networks_LH_Default_PFC_7",
"7Networks_LH_Default_PFC_8",
"7Networks_LH_Default_PFC_9",
"7Networks_LH_Default_PFC_10",
"7Networks_LH_Default_PFC_11",
"7Networks_LH_Default_PFC_12",
"7Networks_LH_Default_PFC_13",
"7Networks_LH_Default_pCunPCC_1",
"7Networks_LH_Default_pCunPCC_2",
"7Networks_LH_Default_pCunPCC_3",
"7Networks_LH_Default_pCunPCC_4",
"7Networks_LH_Default_PHC_1"
)
data3d <- filter(schaefer7_200_3d$ggseg_3d[[1]],
region %in% regions3d) %>%
transmute(
region,
colour2 = case_when(
grepl(paste0("PFC_", c(1, 3, 5, 9, 11, 12), collapse = "|"), region) ~ "#AD23AD",
grepl(paste0("PFC_", c(2, 4, 6, 7, 8, 10, 13), collapse = "|"), region) ~ "#632AAD",
grepl(paste0("Temp_", c(1, 2, 3, 4, 5), collapse = "|"), region) ~ "#1D8CAD",
grepl(paste0("Par_", c(1, 2, 3, 4), collapse = "|"), region) ~ "#31AD88",
grepl(paste0("pCunPCC_", c(1, 2, 3), collapse = "|"), region) ~ "#61AD03",
grepl(paste0("PHC_", c(1), collapse = "|"), region) ~ "#FFA202"
)
)
data3d
# A tibble: 27 × 2
region colour2
<chr> <chr>
1 7Networks_LH_Default_Temp_1 #1D8CAD
2 7Networks_LH_Default_Temp_2 #1D8CAD
3 7Networks_LH_Default_Temp_3 #1D8CAD
4 7Networks_LH_Default_Temp_4 #1D8CAD
5 7Networks_LH_Default_Temp_5 #1D8CAD
6 7Networks_LH_Default_Par_1 #31AD88
7 7Networks_LH_Default_Par_2 #31AD88
8 7Networks_LH_Default_Par_3 #31AD88
9 7Networks_LH_Default_Par_4 #31AD88
10 7Networks_LH_Default_PFC_1 #AD23AD
# ℹ 17 more rows
# ℹ Use `print(n = ...)` to see more rows
ggseg3d(
data3d,
atlas = schaefer7_200_3d,
surface = "inflated",
hemisphere = "left",
colour = "colour2"
) %>%
remove_axes()
Hi there!
Thank you so much for such a wonderful tool.
I'm currently trying to figure out a way to manually assign colours to specific ROIs in the schaefer7_200_3d atlas.
This gives me the following:
![Screen Shot 2022-05-22 at 6 09 53 PM](https://user-images.githubusercontent.com/45542215/169718212-a2cfbe12-9a2f-4a90-98a0-c257e29fa4b8.png)
However, this makes all my ROIs the same pink colour. I was wondering if there is a way that I could go about assigning specific colours using hex to specific regions? For example, assigning #DD2F85 to regions "7Networks_LH_Default_Temp_1","7Networks_LH_Default_Temp_2","7Networks_LH_Default_Temp_3","7Networks_LH_Default_Temp_4","7Networks_LH_Default_Temp_5". Then assigning a different colour to Par regions, to PFC regions, etc.
Thank you very much! Alica