Lucien S.
Lucien S.

Reputation: 5345

iGraph histogram object

I have a graph G of which I what to calculate the degree distribution.

For this, using Python iGraph's "degree_distribution()" seems obvious. However, the function returns an "histogram objects" which I find difficult to deal with.

I use the following code:

dD = G.degree_distribution(bin_width=1)
print(dD)

Which returns:

N = 104, mean +- sd: 12.0000 +- 2.2382
[ 7,  8): *** (3)
[ 8,  9): ** (2)
[ 9, 10): ****** (6)
[10, 11): ************** (14)
[11, 12): ********************* (21)
[12, 13): ****************** (18)
[13, 14): **************** (16)
[14, 15): ********** (10)
[15, 16): ******* (7)
[16, 17): *** (3)
[17, 18): *** (3)
[18, 19): * (1)

I'd like to export the result to R (to use with ggplot2). How to convert this to a format that would be exportable?

Upvotes: 3

Views: 1190

Answers (1)

Tamás
Tamás

Reputation: 48051

list(h.bins()) gives you a list of tuples where each tuple contains the left and right bound of a histogram bin and the number of items in that bin. You can then probably write this into a file and read it from R.

Upvotes: 2

Related Questions