I am trying to compile a graphical depiction of test scores from 50 students. My ultimate goal would be to create 50 variations of the bar chart, one for each student, with only the one student's name on the axis so he/she can see how they compare to the others without disclosing who scored what. In the photo below, I would like to put "Jackson" on the first bar and leave the others blank for the first variation. The second would only have "Smith", etc. Additionally, I would like to split the data based on their year in school, the variable "level".
names <- c("Jackson", "Smith", "Johnson", "Richards", "Matthews", "Redmond", "Phillips")
scores <- c(.99, .65, .73, .89, .88, .92, .87)
level <- c(10,11,10,11,11,11,11)
grades <- cbind.data.frame(names, scores, level)
Gradesplit <- split(grades, grades$level)
plotdata <- function(grades) {
ggplot(data = grades, aes(x = names, y = scores, fill = scores))+
geom_bar(stat = "identity", position = "dodge")+
theme(axis.text.x=element_text(angle= 45, vjust=.5)) +
ggtitle("test scores by level- February 2018", grades$level)}
lapply(Gradesplit, plotdata)
It requires a bit of understanding, but we can make it work. As @richardtelford said, we need to manually build the labels, to do so we can 'loop' on the names, filter the by the level of each name, build a vector of appropriate legnth, and finally build the plot with such labels:
Created on 2018-05-17 by the reprex package (v0.2.0).
I recommend to add some sampling. Then the students can't find patterns and make conclusions. Thus, you can try