I am trying to visualize a heterogeneous graph which nodes are categorical. Here is a dummy graph for implementation:
Input is
graph = UndirectedEdge @@@ {{"u0", "c1"}, {"u1", "c3"}, {"u2", "c0"}, {"u3", "c2"}, {"u4", "c1"}, {"u0", "i0"}, {"u1", "i0"}, {"u2", "i0"}, {"u3", "i1"}, {"u4", "i2"}}
And it looks like this by specifying vertex coordinates.
I would like to customize vertex shape by using VertexShapeFunction
, but I cannot make the pattern matching work, for instance, I would like to make the nodes starts with u
have shape square:
Graph[graph, VertexLabels -> "Name", VertexShapeFunction -> {_?StringStartsQ["u"] -> "Square" }]
I am aware the it should be a pattern, as
CompleteGraph[5, VertexShapeFunction -> {_?EvenQ -> "Star"}, VertexSize -> 0.2]
but I don't know how to make pattern work, I tried:
Cases[{"u1", "p1"}, _?StringStartsQ[#, "u"] &]
I know StringCases
and Select
can easily returns the strings I want, but unfortunately, seems only Cases
with pattern matching would work for VertexShapeFunction
StringCases[{"u1", "p1"}, "u" ~~ _]
Select[{"u1", "p1"}, StringStartsQ[#, "u"] &]