Here I would like to share Five Steps in Twelve lines of R code to draw some plots, histograms, boxplot and pie chart (so many stuff!). It is super easy and convenient! I am sure you will be impressed by the R power, just like I do.
I will be using the SATGPA dataset to see if there is any correlation between students’ GPA and SAT score. Here we go:
Step 1. Set up our work directory:
# Get work directory:
#Set work directory:
Step 2. Read some data and check the data
#Read CSV data into a variable data1:
data1 <- read.csv(“csv/Stat2Data/SATGPA.csv”, header = TRUE)
#Output the data1:
# Display the structure of data1
Step 3. Draw some plots
# Plot the GPA variable of data1
# Plot the GPA variable against the MathSAT variable
# Plot the GPA variable against the VerbalSAT variable
Step 4. How about some histograms!
# Create a histogram for GPA
# Create a histogram for rating, with 20 bins
hist(data1$GPA, breaks = 20)
Step 5. boxplot and pie Chart!
# Create a boxplot of the GPA variable
# Create a pie chart of the table of counts of the GPA
Are you ready to learn some R now? 🙂