Read in Sachi’s NYC Farmers Markets data that is in csv file.
farmers <- read_csv("https://raw.githubusercontent.com/jacshap/Data607/refs/heads/main/nyc_farmers_markets_visitors_wide.csv", col_names = TRUE, show_col_types = FALSE)
knitr::kable(farmers)
| Week | Manhattan_Count | Brooklyn_Count | Queens_Count | Bronx_Count | StatenIsland_Count |
|---|---|---|---|---|---|
| 2025-08-03 | 1842 | 2311 | 1097 | 856 | 402 |
| 2025-08-10 | 1915 | 2468 | 1121 | 903 | 417 |
| 2025-08-17 | 2004 | 2387 | 1180 | 891 | 439 |
| 2025-08-24 | 1962 | 2520 | 1145 | 934 | 455 |
farmers <- farmers %>% pivot_longer(cols = 'Manhattan_Count':'StatenIsland_Count',
names_to = 'Borough',
values_to = "Count")
#clean up
farmers <- farmers %>% mutate(Borough = str_replace_all(Borough, c("_Count"="")))
knitr::kable(farmers)
| Week | Borough | Count |
|---|---|---|
| 2025-08-03 | Manhattan | 1842 |
| 2025-08-03 | Brooklyn | 2311 |
| 2025-08-03 | Queens | 1097 |
| 2025-08-03 | Bronx | 856 |
| 2025-08-03 | StatenIsland | 402 |
| 2025-08-10 | Manhattan | 1915 |
| 2025-08-10 | Brooklyn | 2468 |
| 2025-08-10 | Queens | 1121 |
| 2025-08-10 | Bronx | 903 |
| 2025-08-10 | StatenIsland | 417 |
| 2025-08-17 | Manhattan | 2004 |
| 2025-08-17 | Brooklyn | 2387 |
| 2025-08-17 | Queens | 1180 |
| 2025-08-17 | Bronx | 891 |
| 2025-08-17 | StatenIsland | 439 |
| 2025-08-24 | Manhattan | 1962 |
| 2025-08-24 | Brooklyn | 2520 |
| 2025-08-24 | Queens | 1145 |
| 2025-08-24 | Bronx | 934 |
| 2025-08-24 | StatenIsland | 455 |
Will do 2 analyses suggested by Sachi 1. Compare week-over-week trends by borough (levels + % change). 2. Compute share of total visitors each week (who’s contributing most).
% change = (new value - old value)/old value * 100
perc_change <- farmers %>% group_by(Borough) %>% mutate(lagged_perc = lag(Count)) %>% mutate(percent_change = (Count - lagged_perc)/lagged_perc*100) %>% select(Week, Borough, Count, percent_change)
perc_change <- perc_change[-(1:5),] %>% arrange(Borough)
knitr::kable(perc_change)
| Week | Borough | Count | percent_change |
|---|---|---|---|
| 2025-08-10 | Bronx | 903 | 5.490654 |
| 2025-08-17 | Bronx | 891 | -1.328904 |
| 2025-08-24 | Bronx | 934 | 4.826038 |
| 2025-08-10 | Brooklyn | 2468 | 6.793596 |
| 2025-08-17 | Brooklyn | 2387 | -3.282010 |
| 2025-08-24 | Brooklyn | 2520 | 5.571847 |
| 2025-08-10 | Manhattan | 1915 | 3.963084 |
| 2025-08-17 | Manhattan | 2004 | 4.647520 |
| 2025-08-24 | Manhattan | 1962 | -2.095808 |
| 2025-08-10 | Queens | 1121 | 2.187785 |
| 2025-08-17 | Queens | 1180 | 5.263158 |
| 2025-08-24 | Queens | 1145 | -2.966102 |
| 2025-08-10 | StatenIsland | 417 | 3.731343 |
| 2025-08-17 | StatenIsland | 439 | 5.275779 |
| 2025-08-24 | StatenIsland | 455 | 3.644647 |
ggplot(data=perc_change, aes(x=Week, y=percent_change, fill = Borough)) +
geom_bar(stat="identity", position = "dodge") +
labs(title = "Percent Change per Borough", x = "Week", y = "Percent Change") +
theme_light()