2
$\begingroup$

I am trying to change the thickness of each edge according to its weight using GraphPlot but it doesnt seem to work.

Here's the code I was trying:
edges = {0 -> 1, 0 \[DirectedEdge] 2, 1 \[DirectedEdge] 2, 
   2 \[DirectedEdge] 3, 2 \[DirectedEdge] 4, 2 \[DirectedEdge] 5, 
   3 \[DirectedEdge] 6, 3 \[DirectedEdge] 7, 3 \[DirectedEdge] 8, 
   4 \[DirectedEdge] 9, 4 \[DirectedEdge] 10, 4 \[DirectedEdge] 11, 
   4 \[DirectedEdge] 12, 4 \[DirectedEdge] 13, 4 \[DirectedEdge] 14, 
   5 \[DirectedEdge] 15, 5 \[DirectedEdge] 16, 5 \[DirectedEdge] 17, 
   6 \[DirectedEdge] 7, 6 \[DirectedEdge] 8, 7 \[DirectedEdge] 8, 
   9 \[DirectedEdge] 10, 9 \[DirectedEdge] 11, 9 \[DirectedEdge] 12, 
   9 \[DirectedEdge] 13, 9 \[DirectedEdge] 14, 10 \[DirectedEdge] 11, 
   10 \[DirectedEdge] 12, 10 \[DirectedEdge] 13, 
   10 \[DirectedEdge] 14, 11 \[DirectedEdge] 12, 
   11 \[DirectedEdge] 13, 12 \[DirectedEdge] 14, 
   15 \[DirectedEdge] 16, 15 \[DirectedEdge] 17, 
   16 \[DirectedEdge] 17, 17 \[DirectedEdge] 7, 16 \[DirectedEdge] 6, 
   16 \[DirectedEdge] 7, 16 \[DirectedEdge] 8, 16 \[DirectedEdge] 9, 
   16 \[DirectedEdge] 11, 16 \[DirectedEdge] 13, 
   16 \[DirectedEdge] 14, 16 \[DirectedEdge] 10};
bin = {1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 4, 5, 7, 4, 5, 5, 3, 5, 3, 4, 4, 
   2, 4, 7, 2, 4, 5, 5, 4, 3, 3, 4, 3, 3, 4, 5, 1, 2, 2, 3, 2, 2, 2, 
   2, 2};
weights = bin/100;
GraphPlot[edges, 
  EdgeStyle -> Thread[edges -> (Thickness[#] & /@ weights)]]
LayeredGraphPlot[edges, 
 EdgeStyle -> Thread[edges -> (Thickness[#] & /@ weights)]]

It works with

Graph[edges, 
 EdgeStyle -> Thread[edges -> (Thickness[#] & /@ weights)]]

But it is not really What I needed since I had to move the nodes to have a better angular view...etc. I also need to put vertex label which again doesn't seem to work whenever I put weights(edge thickness).

So here's a photo of what im trying to achieve with a bit more changes, like weight and better angular view on edges: photo1

I was able to produce one with weights but I cant move the nodes to lessen the cross overs and I cant add the node labels at the same time. This is how it looks like: with weights

$\endgroup$
  • $\begingroup$ do you get what you need if you add the option PlotTheme->"Classic" or PlotTheme->"ClassicLabeled"? $\endgroup$ – kglr Oct 12 '19 at 20:32
  • $\begingroup$ ClassicLabeled seems to work for vertex labels. However, I need the weights to show in the thickness of the edges. $\endgroup$ – tintin Oct 13 '19 at 0:08
  • $\begingroup$ change 0 -> 1 to 0 [DirectedEdge] 1 or 0 [UndirectedEdge] 1 works $\endgroup$ – halmir Oct 13 '19 at 6:36
  • $\begingroup$ I've actually got no problem in that. Im looking for a way to change edge thickness in graphPlot $\endgroup$ – tintin Oct 13 '19 at 12:01
1
$\begingroup$

Using the option PlotTheme -> "ClassicLabeled" we get a graphics object that allows you to move vertices around.

GraphPlot[edges, 
  EdgeStyle -> Thread[edges -> (Directive[Gray, Arrowheads[{{5 #, .7}}], 
    Thickness[#]] & /@ weights)],
  PlotTheme -> "ClassicLabeled"]

enter image description here

Using a layout such as "RadialEmbedding" or "SpringEmbedding" we get straight edges which makes it easier to change the location of vertices without having to move many points on the incident edges:

GraphPlot[edges, 
  EdgeStyle -> Thread[edges -> (Directive[Gray, Arrowheads[{{5 #, .7}}], 
        Thickness[#]] & /@ weights)],
  PlotTheme -> "ClassicLabeled", 
  GraphLayout -> "SpringEmbedding"]

enter image description here

With GraphLayout -> "RadialEmbedding" we get

enter image description here

$\endgroup$
  • $\begingroup$ Note: 0 -> 1 in edges in OP is replaced with 0 \[DirectedEdge] 1 as suggested by halmir in comments. $\endgroup$ – kglr Oct 14 '19 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.