Some times, you want to plot the 3d-surfaces from freesurfer. Here, it is easier to use data from freesurfer (like annot and colorlut files) to create colours for the vectors. The data is somewhat more complex than the 2d ggplot polygon version ggseg
ggseg3d()
will create a plotly plot, which is interactive, and provides another type of flexibility to the user. A lot of credit goes to A.M.Winkler and his Brainder work, which supplied us with the first examples of going from .srf
to .ply
files, and whose scripts massively aided us in making this work.
The function ggseg3d()
, is based in the plotly, it is recommended to get a little familiarized with with plotly.
Out-of-the-box, ggseg() works without supplying any extra information. It will create a base plot of the aparc (dkt) brain segmentations. All [...]_3d
atlases have a built in colour
column for default colour plotting of the segments.
The data is stored in tibbles, and looks like so:
To grab all the data for a surface and hemisphere, you should reduce the data to one line, and then unnest()
Particularly notice the mesh
column, which is a list column of lists. In there is all the 6 vectors needed to create the mesh of the tri-surface plot. You’ll also need to notive the label
, annot
and area
columns, which are likely the columns you will be matching on when proviging with your own data for colours. You need to be meticulous when fixing your data, be sure it matches. The function should give you a warning if it’s struggling to match something.
The column you want to use for colour, needs to be supplied to the colour
option, and you’ll likely want to supply it to the text
option, as this will add another line to the plotly hover information.
You can provide custom colour palettes either in hex or R-names
ggseg3d(.data = someData, atlas = dkt_3d,
colour = "p", text = "p",
palette = c("forestgreen", "white", "firebrick"))
ggseg3d(.data = someData, atlas = dkt_3d,
colour = "p", text = "p", palette = c("#ff0000", "#00ff00", "#0000ff"))
If you want to alter the colour of NA
regions, supply na.colour
ggseg3d(.data = someData, atlas = dkt_3d,
colour = "p", text = "p",
na.colour = "black", camera="medial")
ggseg3d(.data = someData, atlas = dkt_3d,
colour = "p", text = "p",
na.colour = "#ffff00", camera="medial")
If you are plotting the sub-cortical structures, you might want to reduce the opacity of the NA
structures, so that you can see the more medial structures. you may also want to add the glassbrain
option, any value above 0 and up to 1 increases the opacity of a glass brain overlay.
You can rotate away all you like. if you want to start from the medial view, you can use the camera
option
There is also a surface of the white-matter
There is much more you can do with the camera options, or by adding extra layout options to plotly. You may want to have a look at these resources if you want to do more complex adaptations to the plots:
https://plot.ly/r/axes/#modifying-axes-for-3d-plots
https://plot.ly/r/trisurf/
https://moderndata.plot.ly/trisurf-plots-in-r-using-plotly/