Submitted by Uday Bhanu Singh
#Loading CSV data
coffeeData <- read_csv("coffee.csv")
head(coffeeData)
## # A tibble: 6 Ă— 14
## ...1 GEOID county hhincome hhincome_log pct_pov pct_pov_log pct_white pop
## <dbl> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 1.31e10 Clayt… 47946 10.8 0.145 -1.86 0.0766 2779
## 2 2 1.31e10 Clayt… 45791 10.7 0.207 -1.53 0.166 5317
## 3 3 1.31e10 Clayt… 34032 10.4 0.159 -1.78 0.201 4485
## 4 4 1.31e10 Clayt… 70364 11.2 0.152 -1.82 0.186 4724
## 5 5 1.31e10 Clayt… 52441 10.9 0.140 -1.90 0.0591 8175
## 6 6 1.31e10 Clayt… 59519 11.0 0.245 -1.37 0.182 1641
## # ℹ 5 more variables: review_count <dbl>, review_count_log <dbl>,
## # avg_rating <dbl>, avg_price <dbl>, n <dbl>
ggplot(coffeeData, aes(x=factor(avg_rating), y=hhincome)) +
geom_boxplot() +
labs(x = 'avg_rating', y = 'hhincome')
The plot indicates a positive correlation between neighborhood income and coffee shop ratings up until an average rating of 4. The 5/5 rating falls out of trend; I am guessing this is because of a few new coffee shops with just a few perfect ratings, so they just roughly follow the median income. 2 star ratings have a lot of outliers, which I am guessing are multiple Starbucks, or other chain locations, that are present in affluent areas. There is a lot of variation and overlap, suggesting that neighborhood income may not be a sufficient indicator for coffee shop quality.
ggplot(coffeeData, aes(x=factor(avg_rating), y=hhincome)) +
geom_boxplot() +
labs(x = 'Average Rating', y = 'Median Annual Household Income ($)') +
facet_wrap(~ county) #Creating seperate plot for each county
This plot breaks down the boxplot from Plot 1 by county. There is significant variation in the distribution of coffee shops across the metro area. Clayton County’s boxplots have few observations and are clustered in the low median income area, which is reflective of the county’s demographics and cannot really be analysed further.
DeKalb county’s resembles the aggregated plot most closely, which could indicate that the most number of coffee shops are present in DeKalb. A somewhat similar trend is seen in Fulton county, but the medians fall much flatter around the $125K band.
In general, this plot indicates that median income of a neighbhorhood, even when grouped by county, is not a sufficient indicator of a coffee location’s quality.
ggplot(coffeeData, aes(x=review_count_log, y=hhincome, color = pct_white)) + #Encoding color as a variable
geom_point(size = 3, alpha = 0.6) +
scale_color_gradientn(colours =
c("#1F01FD", "#FF0002"))+ #Gradient color ends picked from the given example
labs(x = 'Review Count (log)', y = 'Median Annual Household Income',
title = "Scatterplot: Review Count vs. Household Income",
color = "Proportion of residents\nwho self-identified as white") +
facet_wrap(~ county) +
theme_bw() +
theme(
plot.title = element_text(size = 12),
legend.title = element_text(size = 10),
axis.title = element_text(size = 10),
axis.text = element_text(size=8)
)
A visual assessment of this plot suggests a general positive association between the proportion of White residents and median household income across the five counties. Clayton County stands out, with predominantly low-White-proportion census tracts concentrated in a narrow lower-income range.
All five counties show a relatively consistent clustering of logged coffee shop review counts, with most observations falling between approximately 2 and 5. However, Fulton, Cobb, and DeKalb exhibit considerably greater variation in median household income than Clayton and Gwinnett. There don’t seem to be any significant linear relationships between review counts and household income, although some higher-income tracts also have higher review counts. This may indicate that people in higher income areas are more prone to reviewing a coffee shop. Overall, neighborhood racial composition appears more visibly associated with household income than coffee shop review counts are. ## Plot 4
#Using pivot_longer() to create rows for each variable to be explored, so each tract will have 4 rows
plot4 <- coffeeData |>
pivot_longer(cols = c(
"hhincome",
"pct_pov_log",
"pct_white",
"pop"
),
names_to = "vars",
values_to = "vals")
ggplot(plot4, aes(x=review_count_log, y=vals, colour = county))+
geom_point()+
geom_smooth(method = "lm", se=FALSE)+ #Adding regression fit lines for each county
labs(
title = "Scatterplot between logged review count & neighborhood characteristics",
x = "Review Count (log)",
y = "Values",
colour = "County")+
facet_wrap(~ vars, scales="free_y", #Each variable pivoted has separate chart and separate y-axis scales
labeller = as_labeller(c(
"hhincome" = "Median Annual Household Income ($)",
"pct_pov_log" = "Residents Under Poverty Level (%;log)",
"pct_white" = "Residents who self-identify as White (%)",
"pop" = "Total Population")))+
stat_cor( #Using stat_cor to calculate regression values
aes(x=review_count_log, y=vals, group = 1), #Using group = 1 to get values for the entire variable instead of seperate values per county for each variable
color = "black",
r.accuracy = 0.001,
p.accuracy = 0.0001,
show.legend = FALSE
)+
theme_bw()
The scatterplots reveal weak but statistically significant associations between coffee shop review counts and several neighborhood characteristics. Median household income has a weak positive correlation, while poverty exhibits a weak negative correlation. The proportion of White residents has the strongest positive association with review counts (R = 0.236, p < 0.0001), which may indicate a broader metro Atlanta trend that was not seen in plot 4. Total population shows no statistically significant linear relationship with review counts and the scatterplot is just radial.
The county-specific regression lines are relatively stronger for income and racial composition, but still have too much variance. Overall, the correlations are weak, indicating that these neighborhood characteristics individually don’t sufficiently explain the variation in coffee shop review counts.