sorting values before plotting