data loading and manipulation

df <- read.csv("/Users/wangzhichong/Desktop/JOB/COMM7140 TA/Student Final Project/M_Food Delivery Service Apps.csv")
dff <- df %>% select(-(1:17))
variables <- c("UseGrubhub", "UseUberEats", "UseDoorDash", "EaseOfUse", "Price",
               "SpeedOfDelivery", "RestaurantOptions", "DealsDiscounts", "GrubEaseOfUse",
               "GrubPrice", "GrubSpeed", "GrubOptions", "GrubDeals", "GrubBA1", "GrubBA2",
               "GrubBA3", "GrubBA4", "NPSGrub", "UberEaseOfUse", "UberPrice", "UberSpeed",
               "UberOptions", "UberDeals", "UberBA1", "UberBA2", "UberBA3", "UberBA4",
               "NPSUber", "DashEaseOfUse", "DashPrice", "DashSpeed", "DashOptions",
               "DashDeals", "DashBA1", "DashBA2", "DashBA3", "DashBA4", "UPSDash", "Age",
               "Education", "Income")
levels <- as.character(1:10)
for(var in variables) {df[[var]] <- factor(dff[[var]])}
dff$Gender[dff$Gender == 0] <- "M"
dff$Gender[dff$Gender == 1] <- "F"
dff$Gender[dff$Gender == "#NULL!"] <- "O"
dff$Race[df$Race == 1] <- "White (non-Hispanic)"
dff$Race[df$Race == 2] <- "African American"
dff$Race[df$Race == 3] <- "Hispanic"
dff$Race[df$Race == 4] <- "Native American"
dff$Race[df$Race == 5] <- "Asian"
dff$Race[df$Race == 6] <- "Multi-racial"
dff$Race[df$Race == 7] <- "Other"

columns_to_modify <- c("UseGrubhub", "UseUberEats", "UseDoorDash")
for (col in columns_to_modify) {
  dff[[col]] <- as.numeric(as.character(dff[[col]])) 
  dff[[col]][dff[[col]] == 7] <- 6
}

Use of Grubhub by Gender

df1 <- dff %>%
  filter(!is.na(Gender) & !is.na(UseGrubhub))
df1$UseGrubhub <- factor(df1$UseGrubhub,
                        levels = c(1, 2, 3, 4, 5, 6),
                        labels = c("Never", "1 to 5 times", "6 to 10 times", 
                                   "11 to 15 times", "16 to 20 times", "More than 20 times"))


k1<- ggplot(df1, aes(x = Gender, fill = UseGrubhub)) +
  geom_bar(position = "dodge") +
  labs(x = "Gender", y = "Count", fill = "Use Grubhub Frequency") +
  theme_minimal() +
  scale_fill_brewer(palette = "Set1") +
  scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10)) + 
  ggtitle("Use of Grubhub by Gender")
k1

Use of Uber Eats by Gender

dfUber <- dff %>%
  filter(!is.na(Gender) & !is.na(UseUberEats))
dfUber$UseUberEats <- factor(dfUber$UseUberEats,
                             levels = c(1, 2, 3, 4, 5, 6),
                             labels = c("Never", "1 to 5 times", "6 to 10 times", 
                                        "11 to 15 times", "16 to 20 times", "More than 20 times"))

k2<- ggplot(dfUber, aes(x = Gender, fill = UseUberEats)) +
  geom_bar(position = "dodge") +
  labs(x = "Gender", y = "Count", fill = "Use Uber Eats Frequency") +
  theme_minimal() +
  scale_fill_brewer(palette = "Set1") +
  scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10)) + 
  ggtitle("Use of Uber Eats by Gender")
k2

Use of DoorDash by Gender

dfDash <- dff %>%
  filter(!is.na(Gender) & !is.na(UseDoorDash))
dfDash$UseDoorDash <- factor(dfDash$UseDoorDash,
                             levels = c(1, 2, 3, 4, 5, 6),
                             labels = c("Never", "1 to 5 times", "6 to 10 times", 
                                        "11 to 15 times", "16 to 20 times", "More than 20 times"))

k3<-ggplot(dfDash, aes(x = Gender, fill = UseDoorDash)) +
  geom_bar(position = "dodge") +
  labs(x = "Gender", y = "Count", fill = "Use DoorDash Frequency") +
  theme_minimal() +
  scale_fill_brewer(palette = "Set1") +
  scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10)) + 
  ggtitle("Use of DoorDash by Gender")
k3

k1/k2/k3

#income vs. race

df2 <- dff %>%
  filter(!is.na(Race) & !is.na(Income))
df2$Income <- factor(df2$Income,
                     levels = c(1, 2, 3, 4, 5, 6, 7),
                     labels = c("Less than $25K", "$25K to $40K", ">$40K to $55K",
                                ">$55K to $70K", ">$70K to $85K", ">$85K to $100K",
                                ">$100K"))
ggplot(df2, aes(x = Race, fill = Income)) +
  geom_bar(position = "dodge") +
  labs(x = "Race", y = "Count", fill = "Income") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + 
  scale_y_continuous(limits = c(0, 50), breaks = seq(0, 100, by = 10)) +
  scale_fill_brewer(palette = "Set3") +
  ggtitle("Income Distribution by Race")

Prob of using each app

avg_prob_grubhub <- mean(dff$ProbGrubhub, na.rm = TRUE)
avg_prob_ubereats <- mean(dff$ProbUberEats, na.rm = TRUE)
avg_prob_doordash <- mean(dff$ProbDoorDash, na.rm = TRUE)

average_probs_df <- data.frame(
  App = c("Grubhub", "UberEats", "DoorDash"),
  AverageProbability = c(avg_prob_grubhub, avg_prob_ubereats, avg_prob_doordash)
)

ggplot(average_probs_df, aes(x = App, y = AverageProbability, fill = App)) +
  geom_bar(stat = "identity", position = position_dodge()) +
  labs(title = "Average Probability Comparison", x = "App", y = "Average Probability") +
  theme_minimal() +
  scale_fill_brewer(palette = "Set2")

Grubhub NPS vs Usage Frequency

p1<-ggplot(dff, aes(x = NPSGrub, y = UseGrubhub)) +
  geom_hex() +
  labs(title = "Hexbin plot of Grubhub NPS vs Usage Frequency",
       x = "Net Promoter Score for Grubhub",
       y = "Usage Frequency of Grubhub") +
  theme_minimal()
p1

UberEats NPS vs Usage Frequency

p2<- ggplot(dff, aes(x = NPSUber, y = UseUberEats)) +
  geom_hex() +
  labs(title = "Hexbin plot of UberEats NPS vs Usage Frequency",
       x = "Net Promoter Score for UberEats",
       y = "Usage Frequency of UberEats") +
  theme_minimal()
p2

## DoorDash NPS vs Usage Frequency

p3<-ggplot(dff, aes(x = UPSDash, y = UseDoorDash)) +
  geom_hex() +
  labs(title = "Hexbin plot of DoorDash NPS vs Usage Frequency",
       x = "Net Promoter Score for DoorDash",
       y = "Usage Frequency of DoorDash") +
  theme_minimal()
p3

## Usage Frequency of Food Delivery Apps vs Income Level

mean_usage_by_income <- dff %>%
  group_by(Income) %>%
  summarise(
    MeanUseGrubhub = mean(UseGrubhub, na.rm = TRUE),
    MeanUseUberEats = mean(UseUberEats, na.rm = TRUE),
    MeanUseDoorDash = mean(UseDoorDash, na.rm = TRUE)
  ) %>%
  gather(key = "App", value = "Usage", -Income)

mean_usage_by_income$Income <- as.factor(mean_usage_by_income$Income)

ggplot(mean_usage_by_income, aes(x = Income, y = Usage, color = App, group = App)) +
  geom_line() +
  geom_point() +
  labs(title = 'Average Usage Frequency of Food Delivery Apps by Income Level',
       x = 'Income Category',
       y = 'Average Usage Frequency') +
  theme_minimal() +
  scale_color_manual(values = c("blue", "red", "green")) +
  theme(legend.title = element_blank())

## Age vs. Probability of using Grubhub

df6 <- dff %>%
  mutate(AgeGroup = case_when(
    Age == 1 ~ "18 - 25",
    Age == 2 ~ "26 - 35",
    Age == 3 ~ "36 - 45",
    Age == 4 ~ "46 - 55",
    Age == 5 ~ "56 - 65",
    Age == 6 ~ "66 - 75",
    Age == 7 ~ "76 +",
  ))

b1<- ggplot(df6, aes(x = AgeGroup, y = ProbGrubhub, group = AgeGroup)) +
  geom_boxplot(aes(fill = AgeGroup)) +
  labs(title = "Age vs. Probability of Using Grubhub",
       x = "Age Group",
       y = "Probability") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
b1

Age vs. Probability of using Uber Eats

dfUber <- dff %>%
  mutate(AgeGroup = case_when(
    Age == 1 ~ "18 - 25",
    Age == 2 ~ "26 - 35",
    Age == 3 ~ "36 - 45",
    Age == 4 ~ "46 - 55",
    Age == 5 ~ "56 - 65",
    Age == 6 ~ "66 - 75",
    Age == 7 ~ "76 +",
  ))

b2<- ggplot(dfUber, aes(x = AgeGroup, y = ProbUberEats, group = AgeGroup)) +
  geom_boxplot(aes(fill = AgeGroup)) +
  labs(title = "Age vs. Probability of Using Uber Eats",
       x = "Age Group",
       y = "Probability") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
b2

# Age vs. Probability of using DoorDash

dfDash <- dff %>%
  mutate(AgeGroup = case_when(
    Age == 1 ~ "18 - 25",
    Age == 2 ~ "26 - 35",
    Age == 3 ~ "36 - 45",
    Age == 4 ~ "46 - 55",
    Age == 5 ~ "56 - 65",
    Age == 6 ~ "66 - 75",
    Age == 7 ~ "76 +",
  ))

b3<- ggplot(dfDash, aes(x = AgeGroup, y = ProbDoorDash, group = AgeGroup)) +
  geom_boxplot(aes(fill = AgeGroup)) +
  labs(title = "Age vs. Probability of Using DoorDash",
       x = "Age Group",
       y = "Probability") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
b3

b1/b2/b3

Distinctiveness vs Regard

# Grubhub: Distinctiveness vs Regard
ggplot(data = dff, aes(x = GrubBA4, y = GrubBA3)) +
  geom_point() +
  labs(title = 'Grubhub: Distinctiveness vs Regard', x = 'Distinctiveness (BA4)', y = 'Regard (BA3)')

# Uber Eats: Distinctiveness vs Regard
ggplot(data = dff, aes(x = UberBA4, y = UberBA3)) +
  geom_point() +
  labs(title = 'Uber Eats: Distinctiveness vs Regard', x = 'Distinctiveness (BA4)', y = 'Regard (BA3)')

# Door Dash: Distinctiveness vs Regard
ggplot(data = dff, aes(x = DashBA4, y = DashBA3)) +
  geom_point() +
  labs(title = 'Door Dash: Distinctiveness vs Regard', x = 'Distinctiveness (BA4)', y = 'Regard (BA3)')

## Importance of different attributes

dff %>% 
  select(EaseOfUse, Price, SpeedOfDelivery, RestaurantOptions, DealsDiscounts) %>%
  gather(key = "Attribute", value = "Importance") %>%
  ggplot(aes(x = Attribute, y = Importance)) +
  geom_boxplot() +
  labs(title = 'Importance of Different Attributes', x = 'Attribute', y = 'Importance Rating')

Education vs Usage

ggplot(dff, aes(x = as.factor(Education), y = UseUberEats)) +
  geom_boxplot() +
  labs(title = 'Education vs Uber Eats Usage Frequency', x = 'Education Level', y = 'Usage Frequency')

# Education vs Usage for Grubhub using a violin plot
ggplot(dff, aes(x = as.factor(Education), y = UseGrubhub)) +
  geom_violin(trim = FALSE, fill = "skyblue") +
  stat_summary(fun = "quantile", fun.args = list(probs = c(.25, .5, .75)), geom = "crossbar", width = 0.2) +
  labs(title = 'Education vs Grubhub Usage Frequency', x = 'Education Level', y = 'Usage Frequency') +
  theme_minimal()