This R markdown document will show you how to generate cortical plots illustrate your cortical thickness results
1. Install and load the required packages
If you have not previously installed these packages, run the following line without the #
#install.packages(c("readr","ggseg","ggsegDesterieux","ggplot2"))
then load the required packages
library(readr)
library(ggseg)
library(ggsegDesterieux)
library(ggplot2)
2. Generating the cortical plots
The results of the cortical thickness analyses (e.g., ridge/lasso regression beta values) will be entered in this step. The input takes the form of a vector of 148 values, corresponding to all parcellated regions in the cortex. For the purpose of this demonstration, we will generate a vector of 148 random numbers ranging from -1 to 1 and use this vector as the results input
CTresults <- runif(148, min = -1, max = 1)
CTresults
## [1] -0.91073215 0.96666940 -0.71777464 -0.19111152 -0.65153609 -0.74427519
## [7] 0.39670747 -0.84659517 -0.17236815 -0.81607070 -0.80284302 -0.89327522
## [13] 0.95719019 -0.48543213 -0.19999111 0.17302396 -0.87012628 -0.48241033
## [19] -0.96099723 0.22987045 -0.50507876 0.24184768 0.45813063 0.31767478
## [25] 0.50350404 0.89024265 -0.41423484 0.24367375 -0.20169629 -0.21050986
## [31] -0.07867878 0.66467618 0.23422426 0.17527095 -0.19676458 0.82992270
## [37] 0.24579739 -0.23821517 0.67763411 0.45960791 -0.28104162 0.24191683
## [43] -0.49277010 -0.63005321 -0.48724436 -0.83844315 0.18583928 -0.44465389
## [49] -0.40340635 0.84225338 0.48901520 0.92188346 0.54100875 -0.88591766
## [55] 0.62139336 0.26139630 -0.92154080 0.58225728 0.44669942 0.59636644
## [61] -0.72726823 -0.83841999 -0.85432364 -0.18363770 -0.37801287 0.55792579
## [67] -0.64670220 -0.02377861 0.83990540 -0.51744732 0.62027388 0.50457038
## [73] -0.25718581 -0.33021523 -0.59107310 0.90038772 -0.38949342 -0.23069837
## [79] 0.76246125 -0.65667801 0.44918601 0.53746166 -0.28239301 0.13673610
## [85] 0.83463446 0.09701665 -0.20727913 0.86271464 0.43166552 -0.65209981
## [91] -0.48074041 -0.88294938 0.35829874 0.26614579 -0.88893064 -0.56062466
## [97] 0.59690749 0.07036026 0.66494997 -0.02979567 -0.42315079 0.07302134
## [103] 0.30923867 -0.40877430 -0.97389285 -0.81132152 -0.51435746 -0.34914532
## [109] 0.57270736 -0.07648543 -0.02994234 0.22130997 0.19829399 0.18221495
## [115] -0.05940569 -0.18996267 -0.28098130 -0.05414746 -0.79983825 0.61520960
## [121] -0.56455008 0.76448692 0.17372889 0.40634531 0.75147248 0.19657962
## [127] -0.62779131 -0.55667516 -0.73361235 -0.67761784 -0.13432972 0.86266099
## [133] 0.47094153 0.10931495 -0.97250979 0.89408687 -0.48518549 -0.85851040
## [139] -0.69023445 0.20125396 -0.69203625 0.83703215 -0.04573338 -0.68043384
## [145] -0.28801564 -0.85047781 0.65355087 0.32885520
Next, the cortical plots are generated and exported as a png image (“CTplot.png”) to your working directory
CTlabels <- read_csv("https://blogs.ntu.edu.sg/cogbrainhealthlab/files/2021/11/CT_labels.csv") #labels for formatting and rearranging the results
CTlabels$beta<-CTresults #your results input
limits<-c(-max(abs(CTlabels$beta)),max(abs(CTlabels$beta)))
#generate the cortical plots and exporting it as a .png iamge
png(filename ="CTplot.png", width = 2700, height = 2200, res = 300)
ggseg(mapping = aes(fill=beta),atlas = desterieux, position="stacked",color="black",.data=CTlabels) +
scale_fill_gradientn(colours=c("#00BFC4","white","#F8766D"),
na.value = "lightgray",
limits=limits,
breaks=limits,
labels=round(limits,2),
name="Beta",guide = guide_colourbar(title.position ="left"))+
theme(axis.text = element_text(family="sans"),
text = element_text(family="sans",face = "bold"),
plot.margin = unit(c(0,0,0,0), "cm"),
axis.title=element_text(margin = unit(c(0,0,0,0), "cm")),
legend.position="right",
legend.title = element_text(hjust = 0.5, angle=90))
dev.off()
The output image should look something like this: