R codes for permutation and graphics