r codes and plots