Update: Use NearestNeighborGraph
with exact coordinates.
gridGraph[dims_, opt : OptionsPattern[]] :=
NearestNeighborGraph[Tuples[Range /@ dims], opt]
gridGraph[{3, 2}, VertexLabels -> "Name"]
Old answer:
Assuming that you don't just want to change the label that is displayed, but actually change the vertex name, you can do this:
Look at in which order GridGraph
numbers vertices, generate the corresponding desired names with Tuple
, and finally replace the integers with the desired names.
In[]:= g = GridGraph[{2, 3}, VertexLabels -> "Name"]
In[]:= names = Tuples[{Range[3], Range[2]}]
Out[]= {{1, 1}, {1, 2}, {2, 1}, {2, 2}, {3, 1}, {3, 2}}
In[]:= rules = Thread[Range@Length[names] -> names]
Out[]= {1 -> {1, 1}, 2 -> {1, 2}, 3 -> {2, 1}, 4 -> {2, 2}, 5 -> {3, 1}, 6 -> {3, 2}}
In[]:= Graph[
VertexList[g] /. rules, EdgeList[g] /. rules,
VertexLabels -> "Name"
]