I need a Mathematica script, called graph, with three arguments: vert, edges,groups, which produces a graph with vertice labels given in the list vert, and coloured differently, and also with different shapes, according to specified groups. My guess is there must be a simple way to color + shape vertices differently, but I can't find it in the dcumentation. Hence the script I (actually ChatGPT) wrote, which works for coloring only
(*SAIR Example*)
graph[comp_List, edges_List, groups_List : {}] :=
Module[{colorList, vertexColors,
defaultColor = Yellow},(*If groups are provided,
assign colors.Otherwise,set default color*)
If[Length[groups] > 0,(*Define colors and map groups to colors*)
colorList = {Green, Red, Blue, Purple, Orange};
vertexColors =
Flatten[MapThread[
Thread[#1 -> #2] &, {groups,
Take[colorList,
Length[groups]]}]],(*Default to coloring all vertices Yellow \
if groups not specified*)
vertexColors = Thread[comp -> defaultColor]];
(*Use Graph to generate the plot*)
Graph[comp, edges, VertexStyle -> vertexColors,
VertexLabels ->
"Name",(*Directly show names on vertices without extra circles*)
ImageSize -> 500,(*Adjusted image size for smaller output*)
GraphLayout -> "LayeredDigraphEmbedding"]]
(*Example usage*)
(*Define vertices and edges*)
comp = {"S", "A", "I", "R", "S" + "I", "S" + "A", "A" + "I", 2 "A", 0};
edges = {0 -> "S", "S" + "A" -> 2 "A", "S" + "I" -> "A" + "I",
"A" -> "I", "A" -> "R", "S" -> "R", "I" -> "R", "R" -> "S",
"S" -> 0, "A" -> 0, "I" -> 0, "R" -> 0};
(*Default case-all vertices Yellow*)
graph[comp, edges]
(*With groups for custom colors*)
groups = {{"S", "A"}, {"I", "R"}, {"S" + "I", "S" + "A", "A" + "I",
2 "A", 0}};
graph[comp, edges, groups]
But, when I try to add shapes, all hell breaks lose