How to remap graph properties?
Slightly more cumbersome alternative to your sp
(hopefully little less tedious to use):
ClearAll[mapF]
mapF[pr1_ -> pr2_][g_] := SetProperty[g,
pr1 -> Cases[Options@g, Rule[a_, {___, Rule[pr2, v_], ___}] :> Rule[a, v], Infinity]];
mapF[r : (_ -> _) ..][g_] := Fold[mapF[#2][#] &, g, {r}];
g3 = g // mapF[VertexLabels -> "name"]
g4 = g // mapF[VertexLabels -> "name", EdgeWeight -> "weight", VertexSize -> "Faction"];
PropertyValue[{g4, #}, VertexLabels] & /@ VertexList[g4]
PropertyValue[g4, EdgeWeight]
{"4", "5", "3", "3", "3", "3", "2", "2", "2", "3", "1", "3", "2", "2", "2", "2", "6", "3", "4", "5", "1", "2", "2", "2", "3", "4", "5", "1", "3", "2", "2", "2", "3", "3", "3", "2", "3", "5", "3", "3", "3", "3", "3", "4", "2", "3", "3", "2", "3", "4", "1", "2", "1", "3", "1", "2", "3", "5", "4", "3", "5", "4", "2", "3", "2", "7", "4", "2", "4", "2", "2", "4", "2", "3", "3", "4", "4", "5"}
Note: the values of weight
are strings.
With IGraph/M, we can transfer the value of one property into another one. For example, to copy the "weight"
values into EdgeWeight
, use
IGEdgeMap[Identity, EdgeWeight -> IGEdgeProp["weight"], g]
This does not remove "weight"
. It only copies its values into another property.
There is also an operator form for these functions, to allow chaining:
g // IGEdgeMap[#&, EdgeWeight -> IGEdgeProp["weight"]] // IGVertexMap[#&, VertexLabels -> IGVertexProp["name"]]