I'm trying to create a graph to represent transitions between different states of a system. I would like to represent the time the systems spent in a state with the size of the vertex and the frequency of transition between two states with the thickness of the edge connecting the two vertices. In short I need to control the size of vertices and the thickness of edges.
Now that I grasp the difference between Graph and GraphPlot a bit better, I wanted to implement this using the newer Graph
functunality, specifically VertexSize
and EdgeStyle
.
Here is my clumsy attempt:
trans = Uncompress@
"1:eJyVV01vwjAMRfu47U/sv3RKKc2KGsahxw2YOE0aXPff17RJSZD8/HIBga3Efn5+\
dl4/f/rT32q1ujyNH+35cj09+F8v40d1/j1+XY+\
Ht8P30T2Pf9ihbyvn7Y0T3GbjzZtyM5LbYmcP9Els++FdTWJy7EwrOEYzTjbeRkHyODnvB\
adgnb7d8KHi4e3OgBudmb5sB3xsV1CBOTLpymCdv1sp/\
mBlzhq9tJrfqolRC9aSDNSzGPwxFv5f05GAldDVoJKbrgBWJsnCIuFMB/\
28JVXNMR7IQsfVvZSTCD07V79Z78Clo1VLIS+YVn5/2H67Q3h4M83wZr2B4W/\
oCmhaFDXSWysUWcVpH4sElyUTFYsEGxnPRl7nlRgTFoFBu0xGjuDToRLAs5GeeDWqes22H\
ORPLDl/FENXLXCmuVWQanrkBwmT88uGjhh8JgIyYRI91EW4aBoqtOIbg60RxD+IAGjuZC+\
QRSeXfC2qkhGor6gqD60WfdoZTOy8SGu9iONKFEJeVO7eELQGMvOD0UDYaXHN5a6DT5Zlv\
GuYlu2TmhIyD726bP5gSnswmEttWR9puG1wH6WE1VuSBI2sVNA6cfxlK6JIx7utFDE7vI5\
lyAL+Kv09FopgpA9t+\
cIcCcjZMXgYV4YWrHd86DFyR2xpTh012aCEY8sSoy3sX3A0OHUHTjWYWgR8fv/wd/kB";
l = VertexList[Graph[trans]];
(*Weigths for vertices*)
r = RandomReal[{0.5, 1}, Length[l]];
vs = Transpose@{l, r} /. List[a_, b_] -> Rule[a, b];
(*Adjust font size*)
vls = Transpose@{l, r} /.
List[a_, b_] -> Rule[a, Directive[Black, Bold, 20*b]];
(*Weigths for line thicknes*)
rr = RandomReal[{0.1, 1}, Length[DeleteDuplicates@trans]]/100;
es = (First@# -> Directive[Thickness[Last@#], Opacity[.5]]) & /@
Transpose@{DeleteDuplicates@trans, rr};
g = Graph[DeleteDuplicates@trans,
VertexLabels -> Placed["Name", Center],
VertexShapeFunction -> "Capsule", VertexSize -> vs,
VertexLabelStyle -> vls, EdgeStyle -> es,
EdgeShapeFunction ->
GraphElementData["ShortUnfilledArrow", "ArrowSize" -> 0.03]]
But the result is useless (the text is not readable and it's not clear from where to where the arrows are going):
How can I either fix this graph so that it's readable or implement variable vertex sizes and variable edge thickens using GraphLayout
?
EDIT @kguler's comment helps. so using:
esf = Function[
a, (First@
a -> ({Arrowheads[{{.03, 1}}],
Arrow[#1, {.10 + 6 Last@a, .15}]} &))] /@
Transpose@{DeleteDuplicates@trans, rr};
g = Graph[DeleteDuplicates@trans,
VertexLabels -> Placed["Name", Center], VertexSize -> vs,
VertexLabelStyle -> vls, EdgeStyle -> es, EdgeShapeFunction -> esf(*,
EdgeShapeFunction->GraphElementData["ShortUnfilledArrow",
"ArrowSize"->0.03]*)]
I get , which is almost usable.
Is there perhaps a way to draw vertices on top of the edges?
Graph
you could doVertexList[Graph[trans]]
. – Heike Jun 5 '12 at 10:31Property
). – Ajasja Jun 5 '12 at 10:46EdgeShapeFunction
to something likeEdgeShapeFunction -> ({Arrowheads[{{.03, 1}}], Arrow[#1, {.1, .15}]} &)
to avoid too much traffic on top of vertices. – kguler Jun 5 '12 at 11:26Circle
the following works:EdgeShapeFunction -> ({Arrowheads[{{.03, 1}}], Arrow[#1, {.2 #2[[1]] /. vs, .2 #2[[2]] /. vs}]} &)
. – kguler Jun 5 '12 at 15:12