Problem 1

For a data set of your choosing, make a faceted plot using the trelliscopejs package. You may make any type of plot; scatter plot, histogram, etc. but, as mentioned in the discussion below, you must explain why you chose this plot and what you are investigating about the variable you are graphing.

The trelliscope plot must include one cognostic measure of your own. Include a description of what it is and what information this measure gives.

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.6.2
library(trelliscopejs)
## Warning: package 'trelliscopejs' was built under R version 4.6.2
## This package is no longer maintained. Please use the 'trelliscope' package instead (see https://github.com/trelliscope/).
library(tidyverse) # dplyr, tidyr, ...
## Warning: package 'tidyverse' was built under R version 4.6.2
## Warning: package 'tidyr' was built under R version 4.6.2
## Warning: package 'dplyr' was built under R version 4.6.2
## Warning: package 'forcats' was built under R version 4.6.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ lubridate 1.9.5     ✔ tibble    3.3.1
## ✔ purrr     1.2.2     ✔ tidyr     1.3.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

Description 2-3 paragraphs.

Describe the data set. Explain the variable you are graphing in your plots and the reason you are investigating with it. Discuss the reason/motivation you chose the variable to facet on, and what insight or trend you are attempting to investigate. Discuss any challenges you had in making the graphs and how you dealt with these challenges. Name at least one cognostic measure (this can include the cognostic you created or be different) the reader could investigate, and explain any insight they might gain from it.

#Load and explore data

food <- read.csv("global_food_delivery_enriched_market_2026.csv")

delivery <- food %>%
          filter(order_channel == "Online Delivery App")

delivery$time_dist <- delivery$actual_delivery_time_min / delivery$delivery_distance_km
#View(delivery)

#Investigative work

ggplot(delivery, aes(x  = actual_delivery_time_min)) +
  geom_histogram()

summary(delivery$actual_delivery_time_min)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    8.00    8.00   11.60   17.16   21.40   75.00
quantile(delivery$actual_delivery_time_min, c(.01, .99))
##     1%    99% 
##  8.000 71.184
#seeing if there is a correlation between delivery time and weather conditions
ggplot(delivery, aes(x = actual_delivery_time_min, y = weather_condition)) +
  geom_boxplot()

#seeing if there is a correlation between delivery time and peak hour
ggplot(delivery, aes(x = actual_delivery_time_min, y = is_peak_hour)) +
  geom_boxplot()

#seeing if there is a correlation between delivery time and type of cuisine
ggplot(delivery, aes(x = actual_delivery_time_min, y = cuisine_category)) +
  geom_boxplot()

#seeing if there is a correlation between delivery time and city
ggplot(delivery, aes(x = actual_delivery_time_min, y = metro_city)) +
  geom_boxplot()

#Look for number of combinations of city/types of cuisine
delivery %>%
  count(metro_city, cuisine_category) %>%
  arrange(metro_city, cuisine_category)
#create new variables for average delivery time and standard deviation of delivery time at the city, cuisince type level

delivery_cogs <- delivery %>%
  group_by (metro_city, cuisine_category) %>%
  summarise(del_time_sd = sd(actual_delivery_time_min, na.rm = TRUE),
            order_count = n(), 
            .groups = "drop") %>%
  mutate(
    del_time_sd = cog(
      del_time_sd, desc = "Standard deviation of actual delivery time in minutes"))

delivery_plot_data <- delivery %>%
  left_join(
    delivery_cogs, 
    by = c("metro_city", "cuisine_category"))
#View(delivery_plot_data)

#trelliscope, facet by city and cuisine

ggplot(delivery_plot_data, aes(x  = actual_delivery_time_min)) +
geom_histogram(color = "navy", fill = "rosybrown3") +
labs(title = "Time Distribution for Restaurant Deliveries",
     x = "Actual Delivery Time (minutes)",
     y = "Number of Orders")  +

facet_trelliscope(~ metro_city + cuisine_category,
                  name = "Restaurant Delivery Times", 
                  desc = "Data from 12 cities and 7 types of cuisine",
                  nrow = 2, ncol = 4,
                  path = ".",  #puts in same folder as the rmd document 
                  self_contained = TRUE) # Allows an external user to open and interact with the trelliscope)

Writeup

I have decided to use the restaurant price/delivery cost dataset that I used in the Chapter 3 homework. When I did my Chapter 3 homework, I realized that there was far too much data to plot in one scatterplot, so I filtered on New York City data for that assignment. This is a very rich data set that contains several cost variables(order value, discount applied, deliver fee, etc) as well as delivery time and distance, customer ratings, weather conditions, among other variables. My interest was piqued enough from the last assignment to explore this more thoroughly to look for correlations in data. I filtered down on only orders placed online for delivery because I wanted to look at delivery times to see if there is a relation to cities/cuisine types.

I started by creating creating a histogram of delivery time. While that histogram does show that the overwhelming majority of deliveries are made in a very timely fashion, the data points for longer delivery times really intrigued me. I then looked at R’s summary statistics and also the the quantile statistics for 1% and 99%. After that, I created several exploratory box plots to look at the relationship between actual delivery time versus the variables of: weather_condition, is_peak_hour, cuisine_category, and metro_city. Each of these showed some variation in data and made me realize that this was worth exploring further and if the type of cuisine and city could have bearing on delivery times.

I decided to create the delivery time standard deviation variable as a means to research this data. Creating this variable proved to be quite the challenge for me. I went back to review the Data Camp Trelliscope Cognostic Measure pages, I watched YouTube videos on the subject, I reviewed the class lecture notes, and I did general Google searches. Quite frankly, it took a bit for this concept to click with me and took me way longer than I thought that it would take me. I also forgot to use the new table name in my ggplot call and I could not figure out why could not see my new variable; I was very frustrated with myself.

In the charts that I have created, I think that it is useful to include the order count and standard deviation on the charts. I have sorted mine solely on delivery time standard deviation in descending order and have filtered by cuisine type to look at the various different statistics. I also found it interesting to filter by city and look at delivery time by cuisine type. Overall, this is an interesting dataset. I would be curious to see a count of restaurants in the sample because the number of restaurants in the sample geographic area could have significant bearing on the delivery time. For example, if there are only 1 or 2 restaurants doing all of the deliveries I would expect delivery times to take longer.

TH

grading: trelliscope plot[25 points], discussion[25 points]

Note: you can add a url directly to the text and it will be active in the html (and word document if you knit to that)

Example: https://www.google.com

If you want to be fancy and make your url active text, you can do this