Project Report

Author

Marek Chadim

## Load the required Packages
library(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 Source
URL <- "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 Names
beach <- 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 Recode
dat$Beach.Name <- beach

# Mutate with respective year and month
dat <- 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.values
tidy <- na.omit(dat)

# Generate the factors for filtering
year_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.


Datalink:
https://data.cityofchicago.org/Parks-Recreation/Beach-Water-Quality-Automated-Sensors/qmqz-2xku


Abstract:
The following graph has been broken down to 4 different sections to analyze.


  1. Beach Temperature
  2. Beach Wave
  3. Beach Turbidity
  4. Beach Battery Life

Remark: Some data in 2013 were missing for some characteristics so it was neglected for data filtering

Temperature

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

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

Column

Yearly Chicago Beach’s Turbidity Averages

renderPlotly(
ggplotly(graph5 <- tidy %>%
           filter(disp_year == input$year_turb) %>%
           select(Turbidity,Beach.Name) %>%
           group_by(Beach.Name) %>%
           summarize(avg_turbidity = mean(Turbidity)) %>%
           ggplot(aes(x = avg_turbidity, y = Beach.Name))+
           geom_point(color = 'red', size = 2)+
           geom_segment(aes(x = 0, xend = avg_turbidity,y = Beach.Name, yend = Beach.Name), color = "blue") + 
           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 Turbidity (NTU)"))
)

Column

Chicago Beach’s Average Turbidity by Year and Month

renderPlotly(
ggplotly(graph6 <- tidy %>%
           filter(Beach.Name == input$beach_turb) %>%
           select(Turbidity,year_month) %>%
           group_by(year_month) %>%
           summarize(month_avg_turbidity = mean(Turbidity)) %>%
           ggplot(aes(x = month_avg_turbidity, y = year_month))+
           geom_bar(stat = 'identity', fill = "#3A718F")+
           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")) + 
           labs(y = "Year & Month", x = "Average Turbidity (NTU)"))
)

Battery Life

Column

Individual Chicago Beach’s Battery Life Average by Years

renderPlotly(
ggplotly(graph7 <- tidy %>%
           filter(disp_year == input$year_battery) %>%
           select(Battery.Life, Beach.Name) %>%
           group_by(Beach.Name) %>%
           summarize(avg_battery = mean(Battery.Life)) %>%
           ggplot(aes(x = avg_battery, y = Beach.Name))+
           geom_point(color = "#FF9611", size = 2)+
           geom_segment(aes(x = 0, xend = avg_battery, y = Beach.Name, yend = Beach.Name), color = "#1176FF") + 
           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 Battery Life for Sensor"))
)

Column

Chicago Beach’s Battery Life Distribution by Years

renderPlotly(
ggplotly(graph8 <- tidy %>%
           filter(Beach.Name == input$beach_battery & disp_year != "2013") %>%
           select(Battery.Life, disp_year) %>%
           group_by(disp_year) %>%
           ggplot(aes(x = disp_year, y = Battery.Life, 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 =9, face = "bold"),
                 legend.position = "none") + 
           labs(y = "Battery Life", x = "Years"))
)