library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(RColorBrewer)
studentdata <- read.csv("/Users/keyapokhriyal/PokhriyalSTAT3480FinalProjectStudentData.csv")
studentdata <- studentdata %>%
  rename(grade = FinalGrade,  
         Mjob = MothersJob,   
         Fjob = FathersJob,
         reason = ReasonForSchool,
         Walc = WeekendAlcUse)
library(shiny)
library(DT)
## 
## Attaching package: 'DT'
## The following objects are masked from 'package:shiny':
## 
##     dataTableOutput, renderDataTable

2. Shiny App

ui <- fluidPage(
    titlePanel("Investigating the relationship between amount of time spent studying and students' final grade"),
    sidebarLayout(
        sidebarPanel(
            h3("Filter Criteria"),
            sliderInput("studytime", "Study Time Range:",
                        min = 1, max = 4,
                        value = c(1, 4), step = 1),
            sliderInput("grade", "Final Grade Range:",
                        min = 0, max = 20,
                        value = c(0, 20), step = 1)
     ),
        mainPanel(
           DTOutput("filteredData"),
           tags$hr(), 
           )
    )
)
server <- function(input, output) {
  studentdata <- read.csv("/Users/keyapokhriyal/PokhriyalSTAT3480FinalProjectStudentData.csv")
    filteredData <- reactive({
        data <- studentdata[
            studentdata$studytime >= input$studytime[1] & studentdata$studytime <= input$studytime[2] &
            studentdata$grade >= input$grade[1] & studentdata$grade <= input$grade[2],
            ]
        data
    })
        output$filteredData <- renderDT({
        datatable(filteredData(), options = list(pageLength = 10), 
                  filter = 'top', 
                  rownames = FALSE)
    })
}
shinyApp(ui, server)
## PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.
Shiny applications not supported in static R Markdown documents

3. Scatter plot visualizing relationship between study time and final grade by reason for choosing school

ggplot(studentdata, aes(x=studytime, y=grade, color=reason)) +
  geom_point(alpha = 0.5, position=position_jitter(width=0.2, height=0.2)) +
  facet_wrap(~ reason, scales = "free_y") +  
  labs(title="Study Time vs. Final Grade by Reason for Choosing School",
       x="Study Time (hours)",
       y="Final Grade",
       color="Reason for School") +
  theme_minimal() +
  theme(strip.text.x = element_text(size=12, color="blue", face="bold"), 
        strip.background = element_rect(color="blue", fill="#CCCCFF")) + 
  scale_color_brewer(palette="Set1")

studentdata <- read.csv("/Users/keyapokhriyal/PokhriyalSTAT3480FinalProjectStudentData.csv")
library(ggplot2)
library(RColorBrewer)

ggplot(studentdata, aes(x=ReasonForSchool)) +
  geom_bar(fill=brewer.pal(4, "Set1")) +
  labs(title="Distribution of Reasons for Choosing School",
       x="Reason for Choosing School",
       y="Count") +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5))

ggplot(studentdata, aes(x=guardian)) +
  geom_bar(fill=brewer.pal(3, "Set1")) +
  labs(title="Count of Guardian Types",
       x="Guardian",
       y="Count") +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5))

ggplot(studentdata, aes(x=WeekendAlcUse)) +
  geom_histogram(bins=5, fill="aquamarine", color="white") +
  labs(title="Histogram of Weekend Alcohol Use",
       x="Weekend Alcohol Use Level",
       y="Frequency") +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5)) 

ggplot(studentdata, aes(x=FinalGrade)) +
  geom_histogram(bins=20, fill="aquamarine", color="white") +
  labs(title="Distribution of Final Grades",
       x="Final Grade",
       y="Frequency") +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5)) 

ggplot(studentdata, aes(x=ReasonForSchool, y=WeekendAlcUse)) +
  geom_boxplot(fill="aquamarine", outlier.color = "red") +
  labs(title="Weekend Alcohol Use by Reason for Choosing School",
       x="Reason for Choosing School",
       y="Weekend Alcohol Use Level") +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5))