Function to create graph from a text file