# Load necessary library library(ggplot2) library(gridExtra) # Set seed for reproducibility set.seed(123) # Generate example student data num_students <- 15 students <- data.frame( Name = paste("Student", 1:num_students), Scores = sample(60:100, num_students, replace = TRUE), Attendance = sample(60:100, num_students, replace = TRUE) ) # Task 1: Scatter Plot - Scores vs Attendance scatter_plot <- ggplot(students, aes(x = Scores, y = Attendance)) + geom_point(color = "red") + labs( title = "Scatter Plot - Scores vs Attendance", x = "Scores", y = "Attendance" ) # Task 2: Bar Plot - Distribution of Scores bar_plot <- ggplot(students, aes(x = Name, y = Scores)) + geom_bar(stat = "identity", fill = "orange") + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs( title = "Bar Plot - Distribution of Scores", x = "Student Names", y = "Scores" ) # Add a Time column for trend visualization students$Time <- seq_len(num_students) # Task 3: Line Plot - Trend of Scores Over Time line_plot <- ggplot(students, aes(x = Time, y = Scores, group = 1)) + geom_line(color = "purple") + labs( title = "Line Plot - Trend of Scores Over Time", x = "Time", y = "Scores" ) # Task 4: Histogram - Distribution of Scores histogram_plot <- ggplot(students, aes(x = Scores)) + geom_histogram(binwidth = 10, fill = "brown", color = "black") + labs( title = "Histogram - Distribution of Scores", x = "Scores", y = "Frequency" ) # Combine and arrange the plots for easy comparison grid.arrange(scatter_plot, bar_plot, line_plot, histogram_plot, ncol = 2)