The following code produces a graph with vertices N1, N2, and Nw colored yellow, and vertices Fx, Fz, F3, F4 and F5 colored red. For this, I used VertexStyle
. However, separately listing each vertex in VertexStyle
is not efficient for a graph with thousands of N and F vertices.
Is there an automated way to color vertices by the first letter in their name, i.e. the "N" and the "F"?
edges = {N1 -> N2, N2 -> Nw, Fx -> N3, Fx -> F4, N1 -> F4, N1 -> Fz,
N2 -> F3, N2 -> F4, F3 -> F4, F4 -> F5};
Graph[
edges,
GraphLayout -> {"LayeredDigraphEmbedding", "Orientation" -> Left},
VertexLabels -> Placed["Name", Center], VertexSize -> 0.35,
VertexStyle ->
{Fx | Fz | F3 | F4 | F5 -> Red,
N1 | N2 | Nw -> Yellow}
]