sidchop / brainconn

Brainconn - an R package for visualising brain connectivity data in 2D and interactive 3D
https://sidchop.github.io/brainconn/articles/brainconn.html
Other
41 stars 6 forks source link

Positive and negative scales for edges #25

Open hgrotzin opened 2 years ago

hgrotzin commented 2 years ago

Hey Sid!

I wanted to see if it would be possible to add in a second scale for positive and negative edges. I'm trying to replicate the scales in the figure attached.

Thanks! Hannah

brain

sidchop commented 2 years ago

Hey Hannah, I haven't added functionality for two separate colour bars, but you could achieve the same effect using a diverging colour scale with a mid point. e.g: brainconn(atlas = custom_atlas, conmat = c_serum, node.size = 1.5, view = "ortho", edge.width = 0.8, edge.color.weighted = T, edge.color = scale_edge_color_gradient2( low = "red", mid = "white", high ="blue", midpoint = 0, space = "Lab", na.value = "grey50", guide = "edge_colourbar" ))

image

If you want to threshold to make the midpoint -/+ 3.5 like the figure you attached, you will have to threshold the matrix before the brainconn function, as the inbuilt thresholding options in brainconn (thr/uthr) only allow an upper or lower threshold, not both. E.g:

c_serum[c_serum < 3.5 & c_serum > -3.5 ] <- 0 brainconn(atlas = custom_atlas, conmat = c_serum, node.size = 1.5, view = "ortho", edge.width = 0.8, edge.color.weighted = T, edge.color = scale_edge_color_gradient2( low = "red", mid = "white", high ="blue", midpoint = 0, space = "Lab", guide = "edge_colourbar"))

brainconn(atlas = custom_atlas, conmat = c_serum, node.size = 1.5, view = "ortho", edge.width = 0.8, edge.color.weighted = T, edge.color = scale_edge_color_distiller( type = "div", palette = 1, direction = -1, values = NULL, space = "Lab", guide = "edge_colourbar" ))

image image

I am not sure if its possible to grey out the values not plotted (e.g. -3.5 to 3.5), as brainconn doesn't like NA valued in the matrices. Check out the other continuous/gradient scale_edge_color* functions from ggraph, there might be something in there which can do it without NA values.

If you definitely need separate colour scales, some other tools which might be able to do it are: surfice (python), visbrain (python), BrainNet Viewer (MATLAB - probably your best bet), graphpype (python), or nilearn (python).

Best, Sid

hgrotzin commented 2 years ago

great thanks so much! I'll keep playing around with the color options.