I am plotting a biological trasnport network in igraph (in R) where I want to show edges in a color gradient based on an edge attribute (which is a continuous variable called "width" in my case). I do not like the default color palette obtained in:
plot(graph, edge.color=E(graph)$width)
Looking at the igraph plot help I found a way to change this palette using cscale from the scales package:
plot(graph,
edge.color=cscale(E(graph)$width,palette = seq_gradient_pal(low = "yellow",high = "red")))
That works fine and may stick to it. However I was wondering whether I could use either viridis or colorbrewer palettes. I have not figured out how to do it. The main issue is that I cannot manage to assign color coding to all edges. For example if I just do this:
plot(graph,
edge.color=cscale(E(graph)$width,palette = viridis_pal())
I get this warning:
In seq.default(begin, end, length.out = n) :
first element used of 'length.out' argument
And indeed the first color is applied to all edges
If I try to specify the length of all edges:
plot(graph,
edge.color=cscale(E(graph)$width,palette = viridis_pal()(ecount(graph))
I get this error message:
Error in palette(x) : invalid argument type)
Any ideas?