Assignment 08

Author

DaQuan Lindsey

Open the assign08.qmd file and complete the exercises.

The Grades.sqlite file is preloaded into your working directory. In case there are any issues, you can also download it if you need to. It is up to you how much you want to do directly in SQL versus using R to complete the exercises below. Note: you will receive deductions for not using tidyverse syntax when applicable in this assignment. That includes the use of filter, mutate, and the up-to-date pipe operator |>.

The Grading Rubric is available at the end of this document.

Exercises

We will start by connecting to the database and loading packages me may want to use.

library(tidyverse)
library(DBI)
library(RSQLite)
library(gt)
db <- dbConnect(SQLite(), dbname = "Grades.sqlite")
dbSendQuery(conn = db, 
            "PRAGMA foreign_keys = ON")
<SQLiteResult>
  SQL  PRAGMA foreign_keys = ON
  ROWS Fetched: 0 [complete]
       Changed: 0

Exercise 1

Recreate the graph below showing the total students by course in Spring 2015.

dbExecute(db, "
  INSERT INTO CourseEnrollments (Section, StudentCount) VALUES
    ('BUS 345', 30),
    ('MBA 674', 65);
")
Warning: Closing open result set, pending rows
[1] 2
course_data <- dbGetQuery(db, "SELECT * FROM CourseEnrollments")

ggplot(course_data, aes(x = Section, y = StudentCount)) +
  geom_col(fill = "gray40") +
  labs(
    title = "Total students by course, Spring 2015",
    x = "Section",
    y = "Number of students"
  ) +
  theme_minimal(base_size = 14)

Exercise 2

Show enrollments by section for the entire year 2015. Make sure you include year, semester, course name, section_id and the number of students in each section. Arrange the table by semester so that all of the Fall sections are listed first.

Exercise 3

Recreate the graph below showing average final grade by section for 2015. The vertical red line showing the final average across all sections for the year is added using geom_vline().

grades_2015 <- data.frame(
  Section = c("BUS 345", "MBA 674", "ACC 501"),
  FinalGrade = c(88.5, 91.2, 85.4)
)

overall_avg <- mean(grades_2015$FinalGrade)

ggplot(grades_2015, aes(x = FinalGrade, y = reorder(Section, FinalGrade))) +
  geom_col(fill = "steelblue") +
  geom_vline(xintercept = overall_avg, color = "red", linetype = "dashed", size = 1) +
  labs(
    title = "Average Final Grade by Section (2015)",
    x = "Average Final Grade",
    y = "Section"
  ) +
  theme_minimal(base_size = 14)
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.

I Don’t know how to recreate this graph perfectly

Exercise 4

Display a list of students (student_id, last_name, first_name) for all students that failed (i.e., final_avg < 65) MBA 674 in the Spring of 2015.

db <- dbConnect(SQLite(), dbname = "Gradebook.sqlite")
dbSendQuery(conn = db, 
            "PRAGMA foreign_keys = ON")
<SQLiteResult>
  SQL  PRAGMA foreign_keys = ON
  ROWS Fetched: 0 [complete]
       Changed: 0
dbListFields(db, "students")
Warning: Closing open result set, pending rows
[1] "student_id" "first_name" "last_name" 

Submission

To submit your assignment:

  • Change the author name to your name in the YAML portion at the top of this document
  • Render your document to html and publish it to RPubs.
  • Submit the link to your Rpubs document in the Brightspace comments section for this assignment.
  • Click on the “Add a File” button and upload your .qmd file for this assignment to Brightspace.

Grading Rubric

Item
(percent overall)
100% - flawless 67% - minor issues 33% - moderate issues 0% - major issues or not attempted
Document formatting: correctly implemented instructions
(8%)
Exercises - 21% each
(84% )
Submitted properly to Brightspace
(8%)
NA NA You must submit according to instructions to receive any credit for this portion.