Using the igraph package for R, I would like to color the nodes of a network by their degrees. The colors should represent a gradient, for instance from blue to red, or from yellow to red, from the lowest to the highest degree observed in the network.
I've found a working solution here using the functions setNames and colorRampPalette.
Nevertheless, isn't there another solution, using R palettes, like heat.colors or brewer.pal?
Let me give you an example, simulating the kind of network I'm analyzing:
g <- sample_bipartite(8, 20, type = "gnm", m = 29)
degrees <- degree(g)
colors <- heat.colors(length(unique(degrees)))
plot(g,
vertex.color = colors)
You see? The color gradient doesn't match the degree gradient.
How can the order of the colors match the order of the degrees, from lowest to highest?
Thank you very much!
