This is an extra credit assignment completed for EPsy 8261. The purpose of this assignment is to create a tutorial on how we turned a table into a graph. We turned Table 2 from the following reference:
Antia, S. D., Jones, P.B., Reed, S., & Kreimeyer, K. H. (2009) Academic status and progress of deaf and hard-of-hearing students in general education classrooms. Journal of Deaf Studies and Deaf Education, 14(3), 293-311. doi: 10.1093/deafed/enp009
Please follow the steps below to create the graph.
Install ggplot2:
install.packages("ggplot2")
## Error: trying to use CRAN without setting a mirror
Load ggplot2:
library(ggplot2)
Read in data based on Table 2
scores <- read.csv("~/Desktop/Stats 1/scores.csv")
Examine data set
head(scores)
## years mean sd n subject
## 1 1 42.8 19.5 120 1
## 2 2 40.3 20.5 135 1
## 3 3 42.0 21.5 119 1
## 4 4 41.3 20.6 101 1
## 5 5 44.9 18.5 77 1
## 6 1 36.3 22.1 146 2
tail(scores)
## years mean sd n subject
## 19 4 94.6 12.1 143 4
## 20 5 93.7 10.2 120 4
## 21 6 42.0 20.2 552 1
## 22 6 35.7 21.5 604 2
## 23 6 36.9 21.0 600 3
## 24 6 94.0 11.6 730 4
summary(scores)
## years mean sd n subject
## Min. :1.0 Min. :33.8 Min. :10.2 Min. : 77 Min. :1.00
## 1st Qu.:2.0 1st Qu.:36.8 1st Qu.:16.9 1st Qu.:115 1st Qu.:1.75
## Median :3.5 Median :40.8 Median :20.6 Median :138 Median :2.50
## Mean :3.5 Mean :52.3 Mean :18.5 Mean :207 Mean :2.50
## 3rd Qu.:5.0 3rd Qu.:56.6 3rd Qu.:21.4 3rd Qu.:153 3rd Qu.:3.25
## Max. :6.0 Max. :94.6 Max. :22.8 Max. :730 Max. :4.00
Create labels for each subject area
scores$subject <- factor(scores$subject, labels = c("Math", "Reading", "Language/Writing",
"Acad Comp"))
Create Graph
ggplot(data=scores, aes(x=years, y = mean))+ #set the data source and aesthetic
geom_point(size = 3)+ #set the individual point and size
geom_errorbar(aes(ymin=mean-sd, ymax=mean+sd), color="maroon", width =.5, lwd=1)+
#add an errorbar to each mean based on SD. Colored maroon, width of .5, and line width of 1
facet_grid(subject~.)+ #condition on subject
ylab("Average Achievement Scores")+ #change y-axis label
xlab("Year")+ #change x-axis label
geom_hline(aes(yintercept=50), color="black", linetype="dashed") #add a horizontal, dashed black line