Skip to content

Instantly share code, notes, and snippets.

@StefanThoma
Last active July 6, 2021 12:22
Show Gist options
  • Save StefanThoma/26a0c11f6c92a6c65c31d24539873f2d to your computer and use it in GitHub Desktop.
Save StefanThoma/26a0c11f6c92a6c65c31d24539873f2d to your computer and use it in GitHub Desktop.
Visualise grades of a class in R.
pacman::p_load(ggplot2, ggthemes)
# Grade needed to pass
passing.grade <- 4
# BinSize (increment of grades)
binsize <- .25
# Input grades
noten <- c(2.75, 2.5, 6.00, 3.25, 4.25, 1, 3.75, 6, 6, 5.00, 3.75, 5.25, 5.75, 4.25, 5.50, 4.50, 5.50, 4.25, 4.25, 5.25, 5.25, 2.50, 4.75, 4.75, 6.00, 5.25, 4.75, 5.25, 3.75, 3.50, 5.75, 2.50, 4.75, 4.50, 5.25, 5.00, 5.00, 5.50, 5.25, 5.25, 5.00, 3.50, 3.75, 5.00, 4.75, 4.75, 5.25, 5.50, 3.50, 3.75, 3.50, 5.25, 5.00, 5.25, 4.75, 4.75, 4.75, 4.00, 3.25, 5.00)
ggplot2::ggplot(mapping = aes(x = noten)) +
geom_histogram(aes(y = ..count..), binwidth = binsize, color = "white", show.legend = FALSE, alpha = c(rep(.7, length(unique(noten[noten<passing.grade]))), rep(1,length(unique(noten[noten>=passing.grade]))))) +
geom_density(aes(y=binsize*..count..)) +
geom_vline(aes(xintercept=median(noten),
color="median: 4.75"), linetype="dashed") +
geom_vline(aes(xintercept=mean(noten),
color="mean: 4.58"), linetype="dashed", ) +
scale_color_manual(name = "Statistiken", values = c("median: 4.75" = "blue", "mean: 4.58" = "red"))+
scale_x_continuous(breaks = unique(noten)) +
ylab("Häufigkeit") +
xlab("Note") +
ggthemes::theme_tufte()
# Need to adjust the mean value in legend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment