5

Here is a minimal working code from Julia Discourse:

using LightGraphs
using GraphPlot
using Colors

g = graphfamous("karate")

membership = [1,1,1,1,1,1,1,1,2,1,1,1,1,1,2,2,1,1,2,1,2,1,2,1,1,1,1,2,1,1,2,1,1,1]
nodecolor = [colorant"lightgrey", colorant"orange"]
nodefillc = nodecolor[membership]

colors = [colorant"lightgray" for i in  1:78]
colors[42] = colorant"orange"

gplot(g, nodefillc=nodefillc, layout=circular_layout, edgestrokec=colors, edgelabel=1:78)

Which producesenter image description here

I would like to add a legend on top left (or top right) so that I can easily tell what are the meaning of the two types of edges. Additionally, if there is also a way to legend what are the two types of nodes that would be a great plus!

For instance, grey edges would be named: "regular edges" and green edges would be "backup edges". Similarly, grey nodes would be "regular nodes" and orange nodes would be "backup nodes"! I could not find a keyword in gplot for what I am searching!

JKHA
  • 1,800
  • 11
  • 28
  • Is it possible to put the `g` and `circular_layout` objects in your code? – Shayan Nov 29 '22 at 14:15
  • 1
    It's a graph object, this should work `g = smallgraph(:karate)` (taken from [GraphPlots](https://github.com/JuliaGraphs/GraphPlot.jl)) – Zitzero Nov 29 '22 at 14:19
  • @Shayan, I took the MWE from here https://discourse.julialang.org/t/graphplot-how-to-color-edges/17519, but actually, any graph with 4 colors, two for nodes and two for edges is fine for a MWE :) – JKHA Nov 29 '22 at 14:43
  • @Shayan, Indeed you are right, I took the code from the question instead of the selected answer in Julia Discourse. My post is now edited accordingly, thanks ;) – JKHA Nov 29 '22 at 14:44

0 Answers0