# Help ? Plot degree distribution / compile from different networks / legend

**URL:** <https://igraph.discourse.group/t/help-plot-degree-distribution-compile-from-different-networks-legend/1401>\
**Category:** Usage\
**Tags:** R\
**Created:** [31 October 2022 18:47 UTC](https://igraph.discourse.group/t/help-plot-degree-distribution-compile-from-different-networks-legend/1401 "2022-10-31T18:47:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![N\_A](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/n_a/32/870_2.png) [@N\_A](https://igraph.discourse.group/u/N_A)\
**Post date:** [31 October 2022 18:47 UTC](https://igraph.discourse.group/t/help-plot-degree-distribution-compile-from-different-networks-legend/1401/1 "2022-10-31T18:47:32Z")

</div>

I’m a beginner and have some difficulty about degree distribution… Hope someone can help me ?

I want to study the degree distribution of several of my networks. I use degree.distribution function and get results. But when I want to graph them with the plot function there is a problem. Isolated vertices do not seem to be represented.

```auto
> degree.distribution(net.rel_non_lucra)
[1] 0.45454545 0.13636364 0.09090909 0.13636364 0.04545455 0.09090909 0.04545455

```

When I read the results in the console the first number indicates that 45% of the vertices are isolated. This is the case in the data table and in the graph. But when I plot the distribution (and compare it with other networks) the 0.45 are associated with a degree 1.

[![enter image description here](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/dd8d9b41447e40b9a89ebd5e197ba575425bd5e0.png)](https://i.stack.imgur.com/dhGz9.png)

Do I have to modify the steps and the axes etics myself? If yes how ? Or is there an error somewhere else?

1. I would like to know if it is possible (and if so how) to **represent on the same graph the degree distribution of several networks by assigning them different colors in order to compare them.** I have tried two different ways and it does not work.

First test :

```auto
plot(degree.distribution(net.rel_non_lucra,net.ami))

```

Second test :

```auto
distribution.ami <- degree_distribution(net.ami)

distribution.rel_non_lucra <- degree.distribution(net.rel_non_lucra)

plot(distribution.ami, distribution.rel_non_lucra)

```

1. Visualization issue; I have weighted the size of the vertices to their degree but can’t **produce the corresponding legend** ; someone can help me ?

```auto
degre.ami <- degree(net.ami)
degre.ami
V(net.ami)$size <- degre.ami*2 + 17
plot(net.ami,edge.color = "indianred2", vertex.color="gray82", vertex.label.family = "Times", 
     vertex.label.color="black", layout = l)

```

In advance a big thank you, I’m starting to despair of blocking on such simple things…

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [6 November 2022 12:10 UTC](https://igraph.discourse.group/t/help-plot-degree-distribution-compile-from-different-networks-legend/1401/2 "2022-11-06T12:10:22Z")

</div>

I am not an R user, so there are certainly better ways to do this, but:

You can visualize the histogram like this:

```r
g<-sample_gnm(1000,500)
dd<-degree_distribution(g)
plot(x=1:length(dd) - 1, y=dd)

```

Generally, please use the underscore names when they exist, i.e. `degree_distribution` instead of `degree.distribution`. The latter should be considered deprecated.

This question is not really about igraph but about general R usage. While you are welcome to post such questions here, you may get a quicker response [at StackOverflow](https://stackoverflow.com/questions/tagged/r).
