# I load the ggplot2 library, but for this task, I'll use base R's barplot function
library(ggplot2)
# I start by defining the possible grades and simulating the marks for 40 students
grades <- c("A+", "A-", "B+", "B", "C")
Marks <- sample(grades, 40, replace = TRUE, prob = c(.2, .3, .25, .15, .1))
# I use barplot() to create a basic bar chart that shows the frequency of each grade
# The main argument specifies the title of my plot
barplot(table(Marks), 
        main = "Mid-Marks in Algorithms",
        col = "lightblue")  # I want to make my bars visually appealing, so I color them light blue

# I notice that the factor levels are automatically placed on the x-axis in lexicographical order
# To make the chart match the logical order of grades, I use the names.arg parameter
barplot(table(Marks), 
        names.arg = grades,
        main = "Mid-Marks in Algorithms",
        col = c("lightblue", "lightcyan", "lavender", "mistyrose", "cornsilk"))  # I use a palette of colors for variety

# Sometimes, I find horizontal bar charts easier to interpret, so I create one with horiz = TRUE
barplot(table(Marks), 
        names.arg = grades,
        horiz = TRUE,
        col = c("lightblue", "lightcyan", "lavender", "mistyrose", "cornsilk"),
        main = "Mid-Marks in Algorithms")

# Instead of showing raw frequencies, I want to visualize proportions
# This helps me understand the relative distribution of grades
barplot(prop.table(table(Marks)), 
        names.arg = grades,
        col = c("lightblue", "lightcyan", "lavender", "mistyrose", "cornsilk"),
        main = "Mid-Marks in Algorithms")

# I decide to increase the size of the axis labels for better readability using cex.names
barplot(prop.table(table(Marks)), 
        names.arg = grades,
        col = c("lightblue", "lightcyan", "lavender", "mistyrose", "cornsilk"),
        main = "Mid-Marks in Algorithms",
        cex.names = 2)

# Now, I create a matrix to visualize grades across multiple subjects
# The matrix rows represent grades, and columns represent subjects
gradTab <- matrix(c(13, 10, 7, 10, 7, 2, 4, 2, 14, 8, 19, 12, 5, 2, 5),
                  nrow = 5, byrow = TRUE)
colnames(gradTab) <- c("Algorithms", "Operating Systems", "Discrete Math")
rownames(gradTab) <- grades
# I use a stacked bar chart to show how grades are distributed across different subjects
# This allows me to see the total distribution of grades within each subject
barplot(gradTab, 
        col = c("lightblue", "lightcyan", "lavender", "mistyrose", "cornsilk"),
        legend.text = grades,  # I add a legend to identify which color represents which grade
        main = "Mid-Marks in Algorithms")

# I prefer juxtaposed bars to compare grades side-by-side across subjects
# This helps me clearly see how each grade is distributed within each subject
barplot(gradTab, 
        beside = TRUE,
        col = c("lightblue", "lightcyan", "lavender", "mistyrose", "cornsilk"),
        legend.text = grades,
        main = "Mid-Marks in Algorithms")

# Finally, I create a horizontal juxtaposed bar chart for a different visual perspective
# Using horiz = TRUE, I can see the same side-by-side comparison in a horizontal layout
barplot(gradTab, 
        beside = TRUE,
        horiz = TRUE,
        col = c("lightblue", "lightcyan", "lavender", "mistyrose", "cornsilk"),
        legend.text = grades,
        cex.names = 0.75,  # I slightly reduce the size of the names on the axis for better fit
        main = "Mid-Marks in Algorithms")