This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(ggplot2)
library(tidyverse)
## ── 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
library(tidyr)
library(ggpmisc)
## Loading required package: ggpp
## Registered S3 methods overwritten by 'ggpp':
## method from
## heightDetails.titleGrob ggplot2
## widthDetails.titleGrob ggplot2
##
## Attaching package: 'ggpp'
##
## The following object is masked from 'package:ggplot2':
##
## annotate
Directions
Loading Data
coffee <- read.csv("coffee.csv")
Plot 1
ggplot(coffee, aes(x = factor(avg_rating), y = hhincome, fill = factor(avg_rating))) +
geom_boxplot(alpha = 0.85, width = 0.6, outlier.shape = 21, outlier.fill = "white") +
scale_fill_brewer(palette = "YlOrBr") +
theme_minimal(base_size = 14) +
labs(
title = "Household Income by Average Coffee Shop Rating",
x = "Average Rating",
y = "Household Income (USD)",
fill = "Avg Rating",
caption = "Source: 2023 ACS 5-year estimates and Yelp POI data"
) +
theme(
plot.title = element_text(face = "bold", size = 16, hjust = 0.5),
plot.subtitle = element_text(size = 13, hjust = 0.5),
legend.position = "none",
panel.grid.minor = element_blank(),
axis.title = element_text(face = "bold")
)
Figure 1 presents a boxplot examining the distribution of neighborhood median household income across coffee shop rating categories. Coffee shops with an average rating of 4 stars appear to have the highest median neighborhood household income, approximately $105,000. The lowest observed household income is below $5,000, while some coffee shops rated 5 stars are located in neighborhoods with median household incomes of approximately $65,000. The median neighborhood household incomes across the rating categories generally range from approximately $48,000 to $105,000. Coffee shops in the highest-income neighborhoods also exhibit variation in ratings, including ratings of 2 and 4 stars. Overall, the distribution suggests that higher neighborhood income does not consistently correspond to higher coffee shop ratings. Although differences are observed across rating categories, the boxplot alone does not establish a statistically significant relationship between neighborhood income and coffee shop ratings.
Plot 2
ggplot(coffee, aes(x = factor(avg_rating), y = hhincome, fill = factor(avg_rating))) +
geom_boxplot(alpha = 0.85, width = 0.6, outlier.shape = 21, outlier.fill = "white") +
scale_fill_brewer(palette = "YlOrBr") +
facet_wrap(~county, scales = "free_y") +
theme_minimal(base_size = 12) +
labs(
title = "Household Income by Average Coffee Shop Rating",
x = "Average Rating",
y = "Median Annual Household Income (USD)",
fill = "Avg Rating",
caption = "Source: 2023 ACS 5-year estimates and Yelp POI data"
) +
theme(
plot.title = element_text(face = "bold", size = 16, hjust = 0.5),
plot.subtitle = element_text(size = 13, hjust = 0.5),
legend.position = "none",
panel.grid.minor = element_blank(),
axis.title = element_text(face = "bold")
)
Figure 2 illustrates the relationship between coffee shop ratings and neighborhood median household income across five selected Atlanta-area counties. The visual distribution suggests that highly rated coffee shops (4–5 stars) are more frequently observed in neighborhoods within Fulton and DeKalb counties. Median household incomes appear comparatively lower in Clayton County and higher in Cobb and Fulton counties. These patterns suggest a possible positive association between neighborhood income levels and coffee shop ratings, although highly rated establishments may also occur in lower-income areas. Overall, the figure highlights potential socioeconomic differences in the geographic distribution of coffee shop ratings across the five-county study area. However, without a formal statistical test, the observed patterns cannot establish the strength or statistical significance of this relationship.
Plot 3
ggplot(data = coffee) +
geom_point(mapping = aes(x=review_count_log, y=hhincome, color = pct_white ),
size = 5) +
facet_wrap(~county, scales = "free_y") +
theme_minimal(base_size = 12) +
labs(
title = "Reviews by Household Income levels among White Residents accross all counties",
x = "Review count (log)",
y = "Median Annual Household Income (USD)",
color = "White Self-identfying",
caption = "Source: 2023 ACS 5-year estimates and Yelp POI data"
) +
scale_color_gradient(low="darkblue", high="red") +
theme_bw()
theme(
plot.title = element_text(face = "bold", size = 14, hjust = 0.5),
legend.position = "none",
panel.grid.minor = element_blank(),
axis.title = element_text(face = "bold")
)
## <theme> List of 4
## $ axis.title : <ggplot2::element_text>
## ..@ family : NULL
## ..@ face : chr "bold"
## ..@ italic : chr NA
## ..@ fontweight : num NA
## ..@ fontwidth : num NA
## ..@ colour : NULL
## ..@ size : NULL
## ..@ hjust : NULL
## ..@ vjust : NULL
## ..@ angle : NULL
## ..@ lineheight : NULL
## ..@ margin : NULL
## ..@ debug : NULL
## ..@ inherit.blank: logi FALSE
## $ legend.position : chr "none"
## $ panel.grid.minor: <ggplot2::element_blank>
## $ plot.title : <ggplot2::element_text>
## ..@ family : NULL
## ..@ face : chr "bold"
## ..@ italic : chr NA
## ..@ fontweight : num NA
## ..@ fontwidth : num NA
## ..@ colour : NULL
## ..@ size : num 14
## ..@ hjust : num 0.5
## ..@ vjust : NULL
## ..@ angle : NULL
## ..@ lineheight : NULL
## ..@ margin : NULL
## ..@ debug : NULL
## ..@ inherit.blank: logi FALSE
## @ complete: logi FALSE
## @ validate: logi TRUE
Figure 3 illustrates the relationship between coffee shop review counts and median household income across five Atlanta-area counties, with color intensity representing the percentage of residents identifying as White. The distribution suggests a positive association between median household income and review activity, with observations in Fulton, Cobb, and DeKalb generally exhibiting higher review counts and income levels. Clayton County, in contrast, shows comparatively lower income levels and fewer reviews. The color gradient also suggests that areas with higher percentages of White residents tend to coincide with higher household incomes and greater review activity. Overall, these patterns indicate potential associations between neighborhood socioeconomic characteristics, racial composition, and coffee shop review activity. However, the visual patterns alone do not establish statistical significance or causation.
Plot 4
# Reshape the data into long format
coffee_long <- coffee %>%
pivot_longer(
cols = c(hhincome, pct_pov, pct_white, pop),
names_to = "variable",
values_to = "value"
)
# Calculate r and p values for each variable
cor_values <- coffee_long %>%
group_by(variable) %>%
summarise(
r = cor(review_count_log, value, use = "complete.obs", method = "pearson"),
p = cor.test(review_count_log, value, method = "pearson")$p.value
) %>%
mutate(
label = paste0("R = ", round(r, 3), "\n", "P = ", signif(p, 3))
)
# Rename variables for facet labels
variable_labels <- c(
"hhincome" = "Median annual household income",
"pct_pov" = "Residents under poverty level (%)",
"pct_white" = "Residents who self-identify as White (%)",
"pop" = "Total population"
)
# Merge correlation labels with plotting data
coffee_long <- coffee_long %>%
left_join(cor_values, by = "variable")
# Create scatter plot with regression lines and facet-specific r & p
ggplot(data = coffee_long, aes(x = review_count_log, y = value, color = county)) +
geom_point(alpha = 0.7, size = 2) +
geom_smooth(method = "lm", se = FALSE, size = 0.8) +
# Add facet-specific correlation text
geom_text(
data = cor_values,
aes(x = -Inf, y = Inf, label = label),
hjust = -0.1, vjust = 1.5,
size = 4,
inherit.aes = FALSE
) +
facet_wrap(~ variable, scales = "free_y", ncol = 2, labeller = as_labeller(variable_labels)) +
scale_color_brewer(palette = "Dark2") +
labs(
title = "Scatterplot between logged review count and neighborhood characteristics",
x = "Review count (log)",
y = "Value",
color = "County",
caption = "Source: 2023 ACS 5-year estimates and Yelp POI data"
) +
theme_minimal(base_size = 12) +
theme(
plot.title = element_text(face = "bold", size = 14, hjust = 0.5),
panel.grid.minor = element_blank(),
legend.position = "bottom",
axis.title = element_text(face = "bold"),
strip.text = element_text(face = "bold", size = 11)
)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'
Figure 4 presents scatterplots examining the relationship between the logarithm of coffee shop review counts and neighborhood socioeconomic characteristics across five Atlanta-area counties, with separate trend lines for each county. The results indicate a weak but statistically significant positive correlation with median household income (R = 0.164, p < 0.001) and a somewhat stronger positive correlation with the percentage of White residents (R = 0.236, p < 0.001), suggesting higher review activity in wealthier neighborhoods and areas with larger White populations. Conversely, the percentage of residents living below the poverty level shows a weak but statistically significant negative correlation (R = −0.147, p = 0.002), indicating fewer reviews in higher-poverty neighborhoods. Total population shows a very weak, statistically insignificant negative correlation (R = −0.031, p = 0.52), suggesting no meaningful linear relationship with review activity. Here, R represents the correlation coefficient, measuring the strength and direction of the relationship, while p represents the p-value, indicating statistical significance. Overall, the findings suggest that neighborhood socioeconomic characteristics are associated with coffee shop review activity, although these correlations do not establish causation.