Sorting data to fix plot