To begin with, I utilized the flexdashboard library to craft this comprehensive report. The generation of plots and tables involved the utilization of diverse packages, and the corresponding source code is readily available for scrutiny.
For the purposes of this assignment, I opted for the Mobile Food Facility Permit dataset. This dataset, sourced from the Datasf website, undergoes weekly updates, with the most recent version dating back to November 19, 2021, while its inception traces back to September 24, 2012.
The rationale behind selecting this specific dataset lies in its inclusion of geometric information, enabling an exploration of various types of Mobile Food Facilities. The central investigation theme in this assignment revolves around understanding the impact of economic challenges from 2019 to the present on the mobile food business sector in San Francisco. Specifically, I will focus on analyzing the ratio of permits issued or expired for such businesses in previous years.
This dataset encompasses 629 rows and 24 columns, with data provided by the San Francisco Department of Public Works and the dataset owned by Public Works. Mobile Food Facility Permits within the dataset entail information such as the vendor’s name, location, type of food sold, and the current status of the permit. The comprehensive nature of the dataset allows for a nuanced exploration of the dynamics and trends within the mobile food business landscape in San Francisco.
Licensing and Attribution:
In this screenshot, you can see the details of the data set. This data is provided on an ‘as-is’ basis and is subject to change at any time without notice.
In this screenshot you can see the first three columns in the data set.
The Report’s Storyboard.
-I successfully imported the “Mobile_Food_Facility_Permit.csv” file into R, and subsequently, I am populating the data frame using the DataTable (DT) package. This has facilitated the creation of a dynamic data table, courtesy of the DT package, allowing for enhanced interactivity and exploration of the dataset.
Within this data table, an efficient search functionality has been incorporated, enabling users to easily locate specific elements by utilizing the search box located at the top of the table. This feature streamlines the process of sifting through vast datasets, making it more user-friendly and time-effective.
Moreover, the data table is equipped with a sorting mechanism that empowers users to arrange the dataset based on their preferred columns. This sorting functionality not only enhances the visual organization of the data but also facilitates in-depth investigations by allowing users to scrutinize specific aspects of the dataset in a more systematic and structured manner. Whether it’s sorting by dates, numerical values, or categorical variables, this feature provides a versatile tool for comprehensive data analysis.
We can scroll the data table to left or right or up and down to explore the rows and columns.
I also added the option to export or print the data set.
Let’s look at the location and distribution of mobile food businesses in San Francisco.
I created an interactive plot with the leaflet package, which gives the ability to make a selection between business statuses. This package has some great features listed below:
Interactive panning/zooming
Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.
Create maps right from the R console or RStudio.
Embed maps in knitr/R Markdown documents and Shiny apps
Quickly render Spatial objects from the sp package or data frames with latitude/longitude columns.
Use map bounds and mouse events to drive Shiny logic.
In this visual representation, businesses situated in close proximity are delineated by distinct colors accompanied by unique ID numbers. As we engage with the plot by zooming in or clicking on individual circles, an interactive feature unfolds—each marker on the map unveils specific details, encompassing the business’s name and operational hours, if available. Additionally, the information popup encapsulates the type of facility each business represents. The plot further provides the flexibility to filter companies based on their permit status.
Upon scrutiny of the map, a comprehensive breakdown of permit statuses reveals that 428 applicants currently possess expired permits, 125 have permits that are either approved, requested, or issued, and 4 permits are presently suspended. It is noteworthy that the suspended permits appear to be associated with only two applicants, albeit in disparate locations. This discrepancy may indicate a potential error in data entry, warranting further investigation and validation.
As we can see this table contains the information about the applicants. I f we sort the table based on Total_Facility column we can see the highest business name May Catering with 52 trucks and go on.
Now I am going to check the applicant’s permit expiration over the time. The expiration date for each business
in SF has the expiration date on their permit like other businesses which is related to their issue date.
This plot created by “dygraphs” library which is very useful package for time series data sets. The information and details about this library is as below:
Automatically plots xts time series objects (or any object convertible to xts).
Highly configurable axis and series display (including optional second Y-axis).
Rich interactive features including zoom/pan and series/point highlighting.
Display upper/lower bars (e.g. prediction intervals) around series.
Various graph overlays including shaded regions, event lines, and point annotations.
As evident from the visualization, businesses with expiration dates preceding 11/20/2021 have allowed their permits to lapse without renewal. Notably, the plot highlights three prominent peaks occurring on 07/15/2018, 01/15/2021, and 11/15/2021. The latter two instances in 2021 may be indicative of economic challenges in San Francisco, particularly stemming from the onset of the Covid-19 pandemic.
The discernible spikes on 01/15/2021 and 11/15/2021 suggest a substantial impact on the mobile food industry, potentially leading to the discontinuation of operations for a significant number of food trucks and push carts. These dates coincide with a period marked by economic difficulties, possibly precipitated by the ongoing challenges posed by the Covid-19 situation. Consequently, it implies that a considerable portion of the mobile food businesses in San Francisco may currently be inactive or facing operational constraints.
In this section, I employed the “plotly” library to generate an interactive scatter point plot. The displayed plot serves as an insightful representation of permit statuses through scatter points. A conspicuous observation is the substantial gap discernible between expired permits and those that are either approved or requested. Additionally, the plot features a limited number of issued permits and instances of suspended permits.
The Plotly library stands out as an excellent tool for crafting interactive plots, offering enhanced visualization capabilities. Notably, it can be seamlessly integrated with ggplot2, enabling the conversion of static ggplot2 plots into interactive ones.
In this segment, I leverage Plotly to construct a barplot aimed at scrutinizing the status of various facility types. The visual representation reveals a prevalent occurrence of expired permit statuses among trucks. This trend might be attributed to the adverse economic impact experienced by small businesses over the past year. Interestingly, there appears to be a limited number of permit renewal requests, indicating a prevailing trend of businesses remaining inactive.
The discernible impact is notably more pronounced on trucks in comparison to push carts, underscoring the disproportionate challenges faced by the mobile food industry, particularly in the context of truck-based operations.
Ultimately, I employed “plotly” in conjunction with facet_wrap features to generate a representation of business locations across different districts. A notable observation is that the majority of businesses possess expired permits, with a significant concentration in Fire Prevention District number 10, encompassing the Mission Bay and Bay View neighborhoods. Additionally, a noteworthy number of expired permits are associated with businesses situated in downtown San Francisco.
Upon delving into the realm of Mobile Food Businesses in San Francisco, a noteworthy revelation emerged – a staggering 428 food trucks or push carts are currently operating with expired permits. The expiration of these permits can be attributed to a myriad of reasons, and a closer examination through a time series plot sheds light on the alarming trend that has manifested, particularly from 2019 through 2020.
The discernible uptick in expired permits during this period can be largely correlated with the adverse effects of the Covid-19 pandemic. The unprecedented circumstances surrounding the pandemic led to the closure of numerous businesses, a phenomenon that evidently impacted the mobile food sector. Factors contributing to this surge in expired permits include the forced closure of companies, restrictions on outdoor dining, and heightened concerns among the populace regarding the consumption of healthy foods during the pandemic.
The repercussions of these challenges were felt acutely in densely populated neighborhoods, with the epicenters of impact being in areas such as downtown, Mission Bay, and Bay View. The adverse effects were exacerbated in these crowded locales, where the symbiotic relationship between bustling city life and mobile food businesses experienced a discernible downturn.
By dissecting the temporal evolution of permit expirations, it becomes evident that the confluence of external factors, primarily driven by the unprecedented events of 2019 and 2020, has left an indelible mark on the mobile food landscape in San Francisco. As we navigate the complexities of this narrative, it becomes imperative to unravel the intricate web of causation, resilience, and potential avenues for revitalization within this vital sector.
---
title: "Mobile Food Facility Permit"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
editor_options:
markdown:
wrap: 72
---
```{r setup, include=FALSE}
pacman::p_load(flexdashboard, ggplot2, jpeg, DT, rjson, rhandsontable, leaflet, ggmap, dplyr, xts, dygraphs, lubridate, tidyr, plotly, tidyverse)
```
# Title
- Title: Mobile Food Facility in San Francisco
- Author: Abbas Jalili
- Date: 11/6/2021
# Introduction
## Row
### Introduction
To begin with, I utilized the flexdashboard library to craft this
comprehensive report. The generation of plots and tables involved the
utilization of diverse packages, and the corresponding source code is
readily available for scrutiny.
For the purposes of this assignment, I opted for the Mobile Food
Facility Permit dataset. This dataset, sourced from the Datasf website,
undergoes weekly updates, with the most recent version dating back to
November 19, 2021, while its inception traces back to September 24,
2012.
The rationale behind selecting this specific dataset lies in its
inclusion of geometric information, enabling an exploration of various
types of Mobile Food Facilities. The central investigation theme in this
assignment revolves around understanding the impact of economic
challenges from 2019 to the present on the mobile food business sector
in San Francisco. Specifically, I will focus on analyzing the ratio of
permits issued or expired for such businesses in previous years.
This dataset encompasses 629 rows and 24 columns, with data provided by
the San Francisco Department of Public Works and the dataset owned by
Public Works. Mobile Food Facility Permits within the dataset entail
information such as the vendor's name, location, type of food sold, and
the current status of the permit. The comprehensive nature of the
dataset allows for a nuanced exploration of the dynamics and trends
within the mobile food business landscape in San Francisco.
Licensing and Attribution:
- License: <http://opendatacommons.org/licenses/pddl/1.0/>
- Source Link: <http://www.sfgov.org>
## Row
### Screenshot 1
In this screenshot, you can see the details of the data set. This data
is provided on an 'as-is' basis and is subject to change at any time
without notice.
```{r fig.height=8, fig.width=10, echo=FALSE}
im1 <- readJPEG("intro1.jpg")
plot(0:1,0:1,type="n",ann=FALSE,axes=FALSE)
rasterImage(im1,0,0,1,1)
```
### Screenshot 2
In this screenshot you can see the first three columns in the data set.
```{r fig.height=4, fig.width=10, echo=FALSE}
im2 <- readJPEG("intro2.jpg")
plot(0:1,0:1,type="n",ann=FALSE,axes=FALSE)
rasterImage(im2,0,0,1,1)
```
# Analysis {.storyboard}
The Report's Storyboard.
### DT: (This package can help us create the interactive table for data sets with sorting and searching features.) {#sec-dt-(this-package-can-help-us-create-the-interactive-table-for-data-sets-with-sorting-and-searching-features.}
```{r}
df <- read.csv("Mobile_Food_Facility_Permit.csv")
df$ExpirationDate <- substr(df$ExpirationDate, 1, nchar(df$ExpirationDate)-5)
new <- df[!(df$ExpirationDate == ""), ]
new <- new[!(new$Fire.Prevention.Districts == ""), ]
new <- tidyr::drop_na(new)
new$FacilityType <- sub("^$", "Undefined", new$FacilityType)
datatable(new,
style = "auto", class = 'cell-border stripe', extensions = "Buttons",
options = list(pageLength = 7, dom = "Bftrip",buttons = c("copy","csv","excel","pdf","print")))
```
------------------------------------------------------------------------
-I successfully imported the "Mobile_Food_Facility_Permit.csv" file into
R, and subsequently, I am populating the data frame using the DataTable
(DT) package. This has facilitated the creation of a dynamic data table,
courtesy of the DT package, allowing for enhanced interactivity and
exploration of the dataset.
Within this data table, an efficient search functionality has been
incorporated, enabling users to easily locate specific elements by
utilizing the search box located at the top of the table. This feature
streamlines the process of sifting through vast datasets, making it more
user-friendly and time-effective.
Moreover, the data table is equipped with a sorting mechanism that
empowers users to arrange the dataset based on their preferred columns.
This sorting functionality not only enhances the visual organization of
the data but also facilitates in-depth investigations by allowing users
to scrutinize specific aspects of the dataset in a more systematic and
structured manner. Whether it's sorting by dates, numerical values, or
categorical variables, this feature provides a versatile tool for
comprehensive data analysis.
- We can scroll the data table to left or right or up and down to
explore the rows and columns.
- I also added the option to export or print the data set.
### Variables description
```{r}
description <- read.csv("description.csv")
datatable(description)
```
------------------------------------------------------------------------
- In this table, we can see the description of the variables. This
table contains the column name, description, and type of the data
for each column.
- Also, the data set includes the Fire Prevention Districts, Police
Districts, and Supervisor Districts.
### Leaflet: (a JavaScript library for creating dynamic maps that support panning and zooming along with various annotations).
```{r}
new <- new[!(new$Latitude == 0),]
df_s1 <- new%>%
filter(Status == "APPROVED")
df_s2 <- new%>%
filter(Status == "REQUESTED")
df_s3 <- new%>%
filter(Status == "EXPIRED")
df_s4 <- new%>%
filter(Status == "ISSUED")
df_s5 <- new%>%
filter(Status == "SUSPEND")
```
```{r}
leaflet() %>%
addTiles()%>%
addMarkers(lng = df_s1$Longitude, lat = df_s1$Latitude,
popup = paste(df_s1$Applicant, "<br>", df_s1$FacilityType, "<br>", df_s1$dayshours),
group = "APPROVED",
clusterOptions = markerClusterOptions()) %>%
addMarkers(lng = df_s2$Longitude, lat = df_s2$Latitude,
popup = paste(df_s2$Applicant, "<br>", df_s2$FacilityType, "<br>", df_s2$dayshours),
group = "REQUESTED",
clusterOptions = markerClusterOptions()) %>%
addMarkers(lng = df_s3$Longitude, lat = df_s3$Latitude,
popup = paste(df_s3$Applicant, "<br>", df_s3$FacilityType, "<br>", df_s3$dayshours),
group = "EXPIRED",
clusterOptions = markerClusterOptions()) %>%
addMarkers(lng = df_s4$Longitude, lat = df_s4$Latitude,
popup = paste(df_s4$Applicant, "<br>", df_s4$FacilityType, "<br>", df_s4$dayshours),
group = "ISSUED",
clusterOptions = markerClusterOptions()) %>%
addMarkers(lng = df_s5$Longitude, lat = df_s5$Latitude,
popup = paste(df_s5$Applicant, "<br>", df_s5$FacilityType, "<br>", df_s5$dayshours),
group = "SUSPEND",
clusterOptions = markerClusterOptions()) %>%
# Layers control
addLayersControl(
overlayGroups = c("APPROVED","REQUESTED","EXPIRED", "ISSUED", "SUSPEND"),
options = layersControlOptions(collapsed = TRUE))
```
------------------------------------------------------------------------
Let's look at the location and distribution of mobile food businesses in
San Francisco.
I created an interactive plot with the leaflet package, which gives the
ability to make a selection between business statuses. This package has
some great features listed below:
- Interactive panning/zooming
- Compose maps using arbitrary combinations of map tiles, markers,
polygons, lines, popups, and GeoJSON.
- Create maps right from the R console or RStudio.
- Embed maps in knitr/R Markdown documents and Shiny apps
- Quickly render Spatial objects from the sp package or data frames
with latitude/longitude columns.
- Use map bounds and mouse events to drive Shiny logic.
In this visual representation, businesses situated in close proximity
are delineated by distinct colors accompanied by unique ID numbers. As
we engage with the plot by zooming in or clicking on individual circles,
an interactive feature unfolds---each marker on the map unveils specific
details, encompassing the business's name and operational hours, if
available. Additionally, the information popup encapsulates the type of
facility each business represents. The plot further provides the
flexibility to filter companies based on their permit status.
Upon scrutiny of the map, a comprehensive breakdown of permit statuses
reveals that 428 applicants currently possess expired permits, 125 have
permits that are either approved, requested, or issued, and 4 permits
are presently suspended. It is noteworthy that the suspended permits
appear to be associated with only two applicants, albeit in disparate
locations. This discrepancy may indicate a potential error in data
entry, warranting further investigation and validation.
### DT Table to check the Applicants closely.
```{r}
df_rgl <- new%>%select(Applicant, ExpirationDate, FacilityType, Status)
df_rgl$ExpirationDate <- gsub("/","-",df_rgl$ExpirationDate)
df_rgl$ExpirationDate <- mdy(df_rgl$ExpirationDate)
df_rgl1 <- df_rgl%>% group_by(Applicant, FacilityType)%>%
summarize(Total_Facility = sum(!is.na(FacilityType)))%>%
arrange(desc(Total_Facility))
datatable(df_rgl1)
```
------------------------------------------------------------------------
As we can see this table contains the information about the applicants.
I f we sort the table based on Total_Facility column we can see the
highest business name May Catering with 52 trucks and go on.
### Dygraphs: (provides rich facilities for charting time-series data in R and includes support for many interactive features).
```{r}
dy_df2 <- new %>% select(x = ExpirationDate, y = Applicant)
dy_df2$x <- gsub("/","-",dy_df2$x)
dy_df2$x <- mdy(dy_df2$x)
df_ts3 <- dy_df2 %>%
group_by(x)%>%
summarize(total = sum(!is.na(y)))
df_ts4 <- xts(df_ts3$total, df_ts3$x)
dygraph(df_ts4, main = "New Haven Temperatures") %>%
dyRangeSelector()
```
------------------------------------------------------------------------
- Now I am going to check the applicant's permit expiration over the
time. The expiration date for each business
- in SF has the expiration date on their permit like other businesses
which is related to their issue date.
- This plot created by "dygraphs" library which is very useful package
for time series data sets. The information and details about this
library is as below:
- Automatically plots xts time series objects (or any object
convertible to xts).
- Highly configurable axis and series display (including optional
second Y-axis).
- Rich interactive features including zoom/pan and series/point
highlighting.
- Display upper/lower bars (e.g. prediction intervals) around series.
- Various graph overlays including shaded regions, event lines, and
point annotations.
As evident from the visualization, businesses with expiration dates
preceding 11/20/2021 have allowed their permits to lapse without
renewal. Notably, the plot highlights three prominent peaks occurring on
07/15/2018, 01/15/2021, and 11/15/2021. The latter two instances in 2021
may be indicative of economic challenges in San Francisco, particularly
stemming from the onset of the Covid-19 pandemic.
The discernible spikes on 01/15/2021 and 11/15/2021 suggest a
substantial impact on the mobile food industry, potentially leading to
the discontinuation of operations for a significant number of food
trucks and push carts. These dates coincide with a period marked by
economic difficulties, possibly precipitated by the ongoing challenges
posed by the Covid-19 situation. Consequently, it implies that a
considerable portion of the mobile food businesses in San Francisco may
currently be inactive or facing operational constraints.
### Plotly: (provides bindings to the plotly.js library and allows you to translate your ggplot2 graphics into an interactive web-based version easily).
```{r}
gg_df <- new%>% select(Date_time = ExpirationDate, Status, Applicant, FacilityType)
gg_df$Date_time <- gsub("/","-",gg_df$Date_time)
gg_df$Date_time <- mdy(gg_df$Date_time)
p3 <- gg_df %>%
group_by(Date_time, Status)%>% summarise(total = sum(!is.na(Applicant))) %>%
ggplot(aes(Date_time,y = total, fill = Status))+
geom_point(aes(size = total))
ggplotly(p3)
```
------------------------------------------------------------------------
In this section, I employed the "plotly" library to generate an
interactive scatter point plot. The displayed plot serves as an
insightful representation of permit statuses through scatter points. A
conspicuous observation is the substantial gap discernible between
expired permits and those that are either approved or requested.
Additionally, the plot features a limited number of issued permits and
instances of suspended permits.
### Using barchart from Plotly for checking the different types of Facilities and the Permit Status.
```{r}
p <- ggplot(data = gg_df, aes(x = FacilityType, fill = Status)) +
geom_bar(position = "dodge")
ggplotly(p)
```
------------------------------------------------------------------------
The Plotly library stands out as an excellent tool for crafting
interactive plots, offering enhanced visualization capabilities.
Notably, it can be seamlessly integrated with ggplot2, enabling the
conversion of static ggplot2 plots into interactive ones.
In this segment, I leverage Plotly to construct a barplot aimed at
scrutinizing the status of various facility types. The visual
representation reveals a prevalent occurrence of expired permit statuses
among trucks. This trend might be attributed to the adverse economic
impact experienced by small businesses over the past year.
Interestingly, there appears to be a limited number of permit renewal
requests, indicating a prevailing trend of businesses remaining
inactive.
The discernible impact is notably more pronounced on trucks in
comparison to push carts, underscoring the disproportionate challenges
faced by the mobile food industry, particularly in the context of
truck-based operations.
### Utilizing Plotly, I have crafted a scatter plot incorporating facet wrap functionality to differentiate between business locations and their respective districts.
```{r}
p2 <- new%>% select(Applicant, Fire.Prevention.Districts, FacilityType, Police.Districts)%>%
group_by(Police.Districts, FacilityType, Fire.Prevention.Districts)%>%
summarise(total = sum(!is.na(Applicant)))%>%
ggplot(aes(color = FacilityType))+
geom_point(aes(Fire.Prevention.Districts, total, size = total))+
facet_wrap(~Police.Districts, nrow = 1)
ggplotly(p2)
```
------------------------------------------------------------------------
Ultimately, I employed "plotly" in conjunction with facet_wrap features
to generate a representation of business locations across different
districts. A notable observation is that the majority of businesses
possess expired permits, with a significant concentration in Fire
Prevention District number 10, encompassing the Mission Bay and Bay View
neighborhoods. Additionally, a noteworthy number of expired permits are
associated with businesses situated in downtown San Francisco.
# Conclusion
Upon delving into the realm of Mobile Food Businesses in San Francisco,
a noteworthy revelation emerged -- a staggering 428 food trucks or push
carts are currently operating with expired permits. The expiration of
these permits can be attributed to a myriad of reasons, and a closer
examination through a time series plot sheds light on the alarming trend
that has manifested, particularly from 2019 through 2020.
The discernible uptick in expired permits during this period can be
largely correlated with the adverse effects of the Covid-19 pandemic.
The unprecedented circumstances surrounding the pandemic led to the
closure of numerous businesses, a phenomenon that evidently impacted the
mobile food sector. Factors contributing to this surge in expired
permits include the forced closure of companies, restrictions on outdoor
dining, and heightened concerns among the populace regarding the
consumption of healthy foods during the pandemic.
The repercussions of these challenges were felt acutely in densely
populated neighborhoods, with the epicenters of impact being in areas
such as downtown, Mission Bay, and Bay View. The adverse effects were
exacerbated in these crowded locales, where the symbiotic relationship
between bustling city life and mobile food businesses experienced a
discernible downturn.
By dissecting the temporal evolution of permit expirations, it becomes
evident that the confluence of external factors, primarily driven by the
unprecedented events of 2019 and 2020, has left an indelible mark on the
mobile food landscape in San Francisco. As we navigate the complexities
of this narrative, it becomes imperative to unravel the intricate web of
causation, resilience, and potential avenues for revitalization within
this vital sector.