cwatson / brainGraph

Graph theory analysis of brain MRI data
166 stars 48 forks source link

plot.braingraph function #20

Closed Forrestwang1 closed 4 years ago

Forrestwang1 commented 4 years ago

HI Chris, I am wondering whether plot function can help plot same group ROIs in same colour based on coordinates. Here is the example data. The first three are coordinate and the last column is the group.
Thanks~

`

  x y z group
0 -34.0239520958084 -40.1017964071856 -22.0059880239521 3
1 -36.3230769230769 -55.6 -18.4307692307692 2
2 -26.0408163265306 -45.0612244897959 -13.8163265306122 3
3 -28.6739926739927 -35.9267399267399 -14.8791208791209 3
4 -28.3012048192771 -62.1927710843374 -13.2289156626506 3
5 -35.7305699481865 -70.6113989637306 -16.1554404145078 2
6 -44.876404494382 -69.8089887640449 -13.7752808988764 3
7 -24.3027888446215 -58.2709163346614 -8.95617529880478 1
8 -22.3983050847458 -74.8305084745763 -9.33050847457627 3
9 -40.9387755102041 -78.9387755102041 -13.8639455782313 2
10 -18.75 -36.2166666666667 -12.55 3
11 -24.23598820059 -85.9233038348082 -15.4749262536873 2
12 -21.3461538461538 -49.4487179487179 -6.41025641025641 3
13 -39.136 -86.752 -15.936 1

`

cwatson commented 4 years ago

I am not entirely sure if this is what you are asking for, but you would assign a vertex attribute for the group colors, let's say color.group, and then use that in the function call plot(g, vertex.color='color.group')

Forrestwang1 commented 4 years ago

Thanks Chris~I will try it.

Forrestwang1 commented 4 years ago

Hi Chris, I finished reading your guide book online and just tried to solve my question based on your help but still failed, and I am wondering whether you can give me some example code if you do not mind, thanks a lot~

cwatson commented 4 years ago

What did you try? How did it fail? If there is an error, what is the output of traceback()?

Forrestwang1 commented 4 years ago

I got trouble to make g from x, y, z values.

cwatson commented 4 years ago

I still need more information, and you didn't answer my previous questions. I need to know:

There is quite a lot of example code in the User Guide. If you are a beginner using R, you may want to follow some tutorials before you try anything else.

If you just want to create a graph from a data.frame, you would use the igraph function graph_from_data_frame, although you would need more columns than what you specify above.

Forrestwang1 commented 4 years ago

Hi Chris, the code I used is graph_from_data_frame but the code need a edge list but the data does not haver a edge list. The above data is the result from a machine learning, x, y ,z are the coordinates of ROI, and the last column of 'group' is the group number from machine learning results. As what I said before, I am tied by creating the g since there is no edge list. Thanks~

cwatson commented 4 years ago

If your data have no concept of edges, then I suppose you could use the igraph function make_empty_graph, assign vertex attributes for the coordinates and group, and assign colors based on group. However, none of this involves the brainGraph package. The plot.brainGraph function is more-or-less a wrapper for plot.igraph so you can just as easily use that function.

Forrestwang1 commented 4 years ago

Thanks Chris~