library(tidyverse)
library(ggplot2)
library(viridis)
library(tidyr)
library(ggpubr)
data <- read.csv("coffee.csv")
data$avg_rating <- as.factor(data$avg_rating)
ggplot(data = data, aes(x = avg_rating, y = hhincome)) +
geom_boxplot() +
labs(x = "avg_rating", y = "hhincome")
Neighborhoods with coffee shops rated between 3 and 4 have the highest
average median household income, while neighborhoods with coffee shops
rated 1 have the lowest average income. Overall, the higher the coffee
shop score, the more likely it was to be in high-income neighborhoods,
but the distribution of coffee shops with a score of 5 was an
exception.
ggplot(data = data, aes(x = avg_rating, y = hhincome)) +
geom_boxplot() +
labs(x = "Average Yelp Rating", y = "Median Annual Household Income ($)") +
facet_wrap(~county, ncol = 3)
The pattern of Plot 1 is very obvious in Fulton, but there are some
variations in other counties. For example, neighborhoods with coffee
shops rated 5 have the lowest average income in Dekalb County, while
neighborhoods with coffee shops rated 3 have the lowest average income
in Clayton County.
ggplot(data = data, aes(x = review_count_log, y = hhincome, color = pct_white)) +
geom_point(size = 3, alpha = 0.8) +
labs(title = "Scatterplot: Review Count vs. Household Income", x = "Review Count (log)", y = "Median Annual Household Income ($)") +
facet_wrap(~county, ncol = 3) +
scale_color_viridis(name = expression("Proportions of residents\nwho self-identified as white")) +
theme_bw()
In most counties, the higher the percentage of whites, the higher the
average neighborhood income. There does not seem to be a direct
relationship between median income and the number of reviews.
long_data <- data %>%
pivot_longer(cols = c("pct_pov_log", "hhincome", "pct_white", "race.tot"),
names_to = "variables",
values_to = "var_value") %>%
mutate(variables = case_when(
variables == "hhincome" ~ "Median Annual Household Income ($)",
variables == "pct_pov_log" ~ "Percent Residents Under Poverty",
variables == "pct_white" ~ "Percent White Resident",
variables == "race.tot" ~ "Total Population"))
ggplot(data = long_data) +
geom_point(aes(x = review_count_log, y = var_value, color = county), size = 1) +
geom_smooth(aes(x = review_count_log, y = var_value, color = county), method = "lm", se = FALSE) +
stat_cor(aes(x = review_count_log, y = var_value), label.x = -Inf, label.y = Inf, vjust = 1.2, hjust = -0.1, size = 3) +
labs(title = "Scatterplot between logged review count & neighborhood characteristic",
subtitle = "Using Yelp data in Five CountieS Around Atlanta, GA",
x = "Review Count Logged", y = "Values") +
facet_wrap(~variables, scales = "free_y", ncol = 2) +
scale_color_discrete(name = "County") +
theme_bw()
## `geom_smooth()` using formula = 'y ~ x'
Median Annual Household Income and Percent White Residents have a
positive relationship with review count (logged), and Percent Residents
Under Poverty and Total Population have a negative relationship with
review count (logged). Percent White Residents has the strongest
relationship among the 4 variables which means the higher the percentage
of whites in the neighborhood, the higher the review count in that
neighborhood.