You can use ggplot2
package to plot bar graphs. I set some simulation for the data you described. Please see below:
library(tidyverse)
# Setting up reproducable expample
set.seed(123)
k <- 11
l <- 6
max_grade <- 10
m <- matrix(sample(max_grade, k * l, replace = TRUE), ncol = l)
colnames(m) <- paste0("C", 1:l)
rownames(m) <- letters[1:k]
df <- as.data.frame(m)
# Data transformation from wide to long format
df2 <- df %>% as_tibble(rownames = "student_id") %>%
pivot_longer(!student_id, names_to = "class", values_to = "grade")
# Plot bar graphs
# by class
ggplot(df2, aes(grade)) +
geom_bar() +
facet_wrap(~ class) +
ggtitle("Distribution by grade by class")
# total
ggplot(df2, aes(grade)) +
geom_bar() +
ggtitle("Distribution by grade for all classes")
Output:
