[1] "Requesting data from: https://data.cincinnati-oh.gov/resource/rg6p-b3h3.json?$where=business_name='DANA''S'%20OR%20business_name%20like%20'%25LISTERMANN%20BREWING%25'&$select=business_name,action_status,insp_type,action_date,violation_description,violation_comments"
filter(!is.na(violation_description)) %>% # Drop NAs first
count(violation_description, sort = TRUE) %>%
mutate(percent = round(n / sum(n) * 100, 1)) %>%
slice_max(order_by = n, n = 10)
# View it nicely
top_violations
# Create the tabletop_violations <- cinci_food_df %>%filter(!is.na(violation_description)) %>%count(violation_description, sort =TRUE) %>%mutate(percent =round(n /sum(n) *100, 1)) %>%slice_max(order_by = n, n =10)# Display it as a nice tableknitr::kable(top_violations, caption ="Top 10 Most Common Violations")
Top 10 Most Common Violations
violation_description
n
percent
“3717-1-03.4(G)(4) - Violation - RTE TCS, date marking
Date marking was not done in a consistent manner according to the code.” | 10| 9.1| |“3717-1-07.0(B) - Violation - Poisonous/toxic material-working containers
Working containers of poisonous/toxic materials are not labeled.” | 8| 7.3| |“3717-1-03.2(A)(2) - Violation - Bare Hand Contact RTE Food
Food employee was touching ready-to-eat food with bare hands.” | 4| 3.6| |“3717-1-03.2(C)(1) - Violation - Preventing Contamination by Separation, Packaging, and Segregation
Ready-to-eat food was not protected from cross-contamination by raw animal food.” | 4| 3.6| |“3717-1-03.2(M)(2)(a) - Violation - Wiping cloths-use limitation
Wet wiping cloth was not maintained in a sanitizer solution between uses.” | 4| 3.6| |“3717-1-03.2(Y) - Violation - Miscellaneous sources of contamination
Facility did not have accessible instructions for removing food of a choking victim.” | 3| 2.7| |“3717-1-03.2(D) - Violation - Food Storage containers-common name ID
Working containers of food are not properly labeled.” | 3| 2.7| |“3717-1-04.4(A)(1) - Violation - Equipment-good repair and proper adjustment.
Equipment and/or components were not maintained in good working order.” | 3| 2.7|
Source Code
---title: "Final Exam Tempelate" # Name of your HTML outputsubtitle: "BAIS 462"author: "Patrick Berry" # Author nametoc: true # Generates an automatic table of contents.format: # Options related to formatting. html: # Options related to HTML output. code-tools: TRUE # Allow the code tools option showing in the output. embed-resources: TRUE # Embeds all components into a single HTML file. execute: # Options related to the execution of code chunks. warning: FALSE # FALSE: Code chunk sarnings are hidden by default. message: FALSE # FALSE: Code chunk messages are hidden by default. echo: FALSE ---# Introduction and Explanation of Data# Load Libraries```{r}#| label: loading in the libraries#| include: FALSElibrary(tidyverse) # Collection of packages for data manipulation (dplyr), visualization (ggplot2), and morelibrary(httr) # Tools to send HTTP requests (GET, POST) to APIslibrary(jsonlite) # Converts JSON data (from APIs) into R-readable formats like lists or data frameslibrary(magrittr) # Provides piping (%>%) functionality for cleaner and more readable codelibrary(lubridate) # Simplifies working with dates and times (parsing, formatting, converting)```# Load Data```{r}#| label: loading in the datapull_cinci_food_data <-function() {# Base URL base_url <-"https://data.cincinnati-oh.gov/resource/rg6p-b3h3.json?"# Set the business filter inside the function BusinessFilter <-"$where=business_name='DANA''S'%20OR%20business_name%20like%20'%25LISTERMANN%20BREWING%25'"# Also specify which columns you want ColumnSelect <-"&$select=business_name,action_status,insp_type,action_date,violation_description,violation_comments"# Build the full URL URL <-paste0(base_url, BusinessFilter, ColumnSelect)print(paste("Requesting data from:", URL))# Pull the data response <-GET(URL)# Parse JSON into a dataframe raw_data <-content(response, as ="text", encoding ="UTF-8") %>%fromJSON()# Clean and format the dataframe cinci_food_df <- raw_data %>%select(business_name, action_status, insp_type, action_date, violation_description, violation_comments) %>%mutate(action_date =str_remove(action_date, "T.*"), # Remove time partaction_date =ymd(action_date)) # Parse clean date# Return the cleaned dataframereturn(cinci_food_df)}cinci_food_df <-pull_cinci_food_data()glimpse(cinci_food_df)```# Directed Analysis top_violations \<- cinci_food_df %\>%filter(!is.na(violation_description)) %\>% \# Drop NAs firstcount(violation_description, sort = TRUE) %\>%mutate(percent = round(n / sum(n) \* 100, 1)) %\>%slice_max(order_by = n, n = 10)\# View it nicelytop_violations```{r}#| label: top-violations-kable#| echo: true# Create the tabletop_violations <- cinci_food_df %>%filter(!is.na(violation_description)) %>%count(violation_description, sort =TRUE) %>%mutate(percent =round(n /sum(n) *100, 1)) %>%slice_max(order_by = n, n =10)# Display it as a nice tableknitr::kable(top_violations, caption ="Top 10 Most Common Violations")```