1

I'm trying to make a frequency distribution of grades (1:10) as well as its cum frequency.

enter image description here

the letter a, b, c, d, ... represents students and C1:C6 represents Course 1 till 6.

Could you advise how to create frequence distribution of grades and plot them.

Artem
  • 3,304
  • 3
  • 18
  • 41
  • 1
    Provide the data using `dput(x)` instead of image. It would be helpful if you can add expected outout. – Nad Pat Nov 10 '21 at 12:49

1 Answers1

0

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: bar graph by class bar graph total

Artem
  • 3,304
  • 3
  • 18
  • 41