# Graph with $\{a,b\}$ as Vertex Instead of Number

I'm trying to create a graph which has $\{a,b\}$ as labels:

g := Graph[{1 \[UndirectedEdge] 9, 1 \[UndirectedEdge] 10,
1 \[UndirectedEdge] 8, 10 \[UndirectedEdge] 2,
10 \[UndirectedEdge] 5, 9 \[UndirectedEdge] 3,
9 \[UndirectedEdge] 6, 8 \[UndirectedEdge] 7,
8 \[UndirectedEdge] 4, 7 \[UndirectedEdge] 3,
7 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 2,
6 \[UndirectedEdge] 4, 5 \[UndirectedEdge] 3,
5 \[UndirectedEdge] 4}]


Any help would be appreciated.

-
How can you detect Petersen-Graph-ness? – Loie Benedicte Aug 4 '13 at 18:56

Not sure what style you prefer, I'm showing you how to label both the vertices and the edges.

For clarity, let's define the edges into its own variable:

v = {1 \[UndirectedEdge] 9, 1 \[UndirectedEdge] 10, 1 \[UndirectedEdge] 8, 10 \[UndirectedEdge] 2,  10 \[UndirectedEdge] 5, 9 \[UndirectedEdge] 3, 9 \[UndirectedEdge] 6, 8 \[UndirectedEdge] 7, 8 \[UndirectedEdge] 4, 7 \[UndirectedEdge] 3, 7 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 4, 5 \[UndirectedEdge] 3, 5 \[UndirectedEdge] 4};


Edge label:

edgeLabels = (# -> #) & /@ v;
g = Graph[v, EdgeLabels -> edgeLabels]


Vertex label:

vertexLabels = (# -> #) & /@ Range[10];
g = Graph[v, VertexLabels -> vertexLabels]

-

You can enter graph vertices and edges as strings and display using VertexLabels->"Name". For illustration purposes using the graph g provided:

graph=UndirectedEdge @@ CharacterRange["a", "j"][[#]] & /@
List @@@ EdgeList[g]
Graph[graph,VertexShapeFunction->"Circle",VertexLabels->Placed["Name",Center],VertexStyle->White,VertexSize->0.5]


yields:

-

Simple way to do this:

Graph[{1 \[UndirectedEdge] 9, 1 \[UndirectedEdge] 10,
1 \[UndirectedEdge] 8, 10 \[UndirectedEdge] 2,
10 \[UndirectedEdge] 5, 9 \[UndirectedEdge] 3,
9 \[UndirectedEdge] 6, 8 \[UndirectedEdge] 7, 8 \[UndirectedEdge] 4,
7 \[UndirectedEdge] 3, 7 \[UndirectedEdge] 2,
6 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 4, 5 \[UndirectedEdge] 3,
5 \[UndirectedEdge] 4},
VertexLabels -> {1 -> "A", 2 -> "B", 3 -> "A", 4 -> "B", 5 -> "A",
6 -> "B", 7 -> "A", 8 -> "B", 9 -> "A", 10 -> "B"}]


-
Any reason behind the downvotes ? – Sektor Jun 19 '14 at 12:40