plot.graph() is the last created graph, so its index should be plot.graphCount() -1
You could also compare the unknown graph with all graphs in plot
for(int i = 0; i < plot.graphCount(); ++i) if(plot.graph(i) == unknownGraph) { //i is the index of the graph break; }