2025-01-10

Introduction

This project corresponds to the final assignment of the Developing Data Products Coursera course by Johns Hopkins University. The main goal of this project is to create a shiny application to be deployed on a shiny server. The link for the application is https://sgrasdal.shinyapps.io/Air_Quality_Analysis/

In order to do the project, I used the ‘airquality’ dataset. The application performs a brief analysis on this dataset using some barplots and scatterplots. The user can choose the analysis he desires using four radio buttons.

Dataset overview

The data used is from the R Studio data sets and describes the air quality in New York during the summer of 1973. There are 153 observations and 6 variables.

##   Ozone Solar.R Wind Temp Month Day
## 1    41     190  7.4   67     5   1
## 2    36     118  8.0   72     5   2
## 3    12     149 12.6   74     5   3
## 4    18     313 11.5   62     5   4
## 5    NA      NA 14.3   56     5   5
## 6    28      NA 14.9   66     5   6

UI Code

# Loading libraries
library(shiny)

# Creating some radio buttons in order to let the user choice the data to analyze with a scatter plot
shinyUI(fluidPage(
        titlePanel("A brief analysis of New York Airquality in 1973"),
        sidebarLayout(
                sidebarPanel(
                        #        helpText("Choose what kind of data you want to look at"),
                        radioButtons("modelType",
                                     label = "Which kind of analysis do you want?",
                                     choices =  list("Correlation analysis" = 1,
                                                     "Solar Radiation vs Temperature w/ Ozone Levels" = 2,
                                                     "Wind vs Temperature w/ Ozone Levels" = 3,
                                                     "Average Temperature per Month" = 4, 
                                                     "Temperature per Month w/ Ozone Levels" = 5),
                                     selected = 1)
                ),
                mainPanel(
                        plotOutput("varPlot")
                )
        )
))

Some server code

shinyServer(function(input, output) {
        
        reactive({input$modelType
                
        })
        
        observe({
                if (input$modelType == 1) {
                        output$varPlot <- renderPlot({ #This is our first plot option (correlation matrix)
                                ggpairs(df, lower = list(continuous = "smooth", aes(color = Month)), title = "Some insights abouts correlations"
                                        #columnLabels = c("Crime", "Nitrogren Oxide", "Age", "Tax", "Lower Status","Black Pop.")
                                ) +
                                        theme_minimal()+
                                        theme(plot.title = element_text(hjust = 0.5)) +
                                        theme(plot.title = element_text(color="black", size=20, face="bold.italic"))
                        })