## Load the required Packageslibrary(flexdashboard)library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.0
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
library(shiny)library(dplyr)library(lubridate)# Obtain Raw Data from SourceURL <-"https://data.cityofchicago.org/api/views/qmqz-2xku/rows.csv?accessType=DOWNLOAD"download.file(URL,"bwq.csv",method ="curl")# Execute Data Import while removing the missing data entries.dat <-read.csv("bwq.csv", header =TRUE, na.strings =c("","NA","0",0)) dat$Measurement.Timestamp <-parse_date_time(dat$Measurement.Timestamp, "mdy_HMS")# Rename Beach to Simplify Beach Namesbeach <-recode(dat$Beach.Name, "63rd Street Beach"="63rd Street", "Calumet Beach"="Calumet", "Montrose Beach"="Montrose", "Ohio Street Beach"="Ohio Street", "Osterman Beach"="Osterman", "Rainbow Beach"="Rainbow")# Replace Parameter Name after Recodedat$Beach.Name <- beach# Mutate with respective year and monthdat <- dat %>%mutate(disp_year =year(Measurement.Timestamp), disp_month =month(Measurement.Timestamp)) %>%mutate(year_month =paste(disp_year, disp_month, sep ="_")) %>%select(-Transducer.Depth) %>%filter(Wave.Height >0) %>%arrange(Measurement.Timestamp)dat$disp_year <-as.character(dat$disp_year)dat$disp_month <-as.character(dat$disp_month)# Clean Data with na.valuestidy <-na.omit(dat)# Generate the factors for filteringyear_factor <-seq(min(tidy$disp_year),max(tidy$disp_year),1)wave_year <-c(2014, 2015, 2016, 2018, 2019, 2020, 2021)beach_factor <-unique(tidy$Beach.Name)
Summary
Column
Background:
The data was gathered from the city of Chicago’s beach data accumulated from 2013 to 2021 during the summer time. Data filtering and ensure the correct data was displayed to ensure no missing data or zeroes presented.
Abstract: The following graph has been broken down to 4 different sections to analyze.
Beach Temperature
Beach Wave
Beach Turbidity
Beach Battery Life
Remark: Some data in 2013 were missing for some characteristics so it was neglected for data filtering
Temperature
Input
Temperature Graph Input
selectInput(inputId ="beach_temp",label ="Select the beach to display for temperature progress",choices = beach_factor,multiple =FALSE,selected = beach_factor[2])
sliderInput(inputId ="year_temp",label ="Select the year to display for individual beach's average temperature",min =min(year_factor),max =max(year_factor),value = year_factor[1])
Column
Chicago Beaches’ Temperature Distribution by Years
renderPlotly(ggplotly(graph1 <- tidy %>%filter(Beach.Name %in% input$beach_temp & disp_year >="2014") %>%ggplot(aes(x = disp_year, y = Water.Temperature, fill = disp_year)) +geom_boxplot()+theme(axis.text.y =element_text(size =9),axis.text.x =element_text(size =9),axis.title =element_text(size =9, face ="bold"),title =element_text(size =10, face ="bold"),legend.title =element_text(size =9),legend.text =element_text(size =9),legend.key.width =unit(0.5, 'cm'),legend.key.height =unit(0.5, 'cm'),legend.key.size =unit(0.5, 'cm'),legend.position ="none") +labs(x ="Year", y ="Temperature (Celsius)")))
Column
Chicago Beaches’ Temperature Average by Years
renderPlotly(ggplotly(graph2 <- tidy %>%filter(disp_year == input$year_temp) %>%select(Water.Temperature,Beach.Name) %>%group_by(Beach.Name) %>%summarize(avg_watertemp =mean(Water.Temperature)) %>%ggplot(aes(x = avg_watertemp, y = Beach.Name))+geom_point(color ='#2F8C81', size =2)+geom_segment(aes(x =0, xend = avg_watertemp,y = Beach.Name, yend = Beach.Name), color ="red") +theme(axis.text.y =element_text(size =9),axis.text.x =element_text(size =9),axis.title =element_text(size =9, face ="bold"),title =element_text(size =9, face ="bold"),legend.position ="none") +labs(y ="Chicago Beach Location", x ="Average Temperature (Celsius)") ))
Wave
Input
Wave Graph Input
selectInput(inputId ="year_wave",label ="Select the year to observe the yearly progress for individual beach's wave height distribution",choices = wave_year,multiple =FALSE,selected = wave_year[1])
selectInput(inputId ="beach_wave",label ="Select the beach to observe the wave period's distribution",choices = beach_factor,multiple =FALSE,selected = beach_factor[3])
Column
Chicago Beaches’ Yearly Wave Height’s Distribution
renderPlotly(ggplotly(graph3 <- tidy %>%filter(disp_year == input$year_wave) %>%ggplot(aes(x = Beach.Name, y = Wave.Height, fill = Beach.Name)) +geom_violin()+theme(axis.text.y =element_text(size =9),axis.text.x =element_text(size =9),axis.title =element_text(size =9, face ="bold"),title =element_text(size =9, face ="bold"),legend.title =element_text(size =9),legend.text =element_text(size =9),legend.key.width =unit(0.5, 'cm'),legend.key.height =unit(0.5, 'cm'),legend.key.size =unit(0.5, 'cm'),legend.position ="none") +labs(x ="Chicago Beach Location", y ="Wave Height (m)") ))
Column
Chicago Beaches’ Yearly Wave Period’s Distribution
renderPlotly(ggplotly(graph4 <- tidy %>%filter(Beach.Name == input$beach_wave) %>%filter(disp_year !="2013"& disp_year !="2017") %>%select(Wave.Period,disp_year) %>%ggplot(aes(x = disp_year, y = Wave.Period, fill = disp_year)) +geom_violin()+theme(axis.text.y =element_text(size =9),axis.text.x =element_text(size =9),axis.title =element_text(size =9, face ="bold"),title =element_text(size =9, face ="bold"),legend.title =element_text(size =9),legend.text =element_text(size =9),legend.key.width =unit(0.5, 'cm'),legend.key.height =unit(0.5, 'cm'),legend.key.size =unit(0.5, 'cm'),legend.position ="none") +labs(x ="Years", y ="Wave Period")))
Turbidity
Input
Turbidity Graph Input
sliderInput(inputId ="year_turb",label ="Select the year to observe the yearly progress for individual beach's average turbidity",min =min(year_factor),max =max(year_factor),value = year_factor[1])
selectInput(inputId ="beach_turb",label ="Select the beach to observe the turbidity's year by month average",choices = beach_factor,multiple =FALSE,selected = beach_factor[1])