---
title: "Lab Assignment 3"
subtitle: "Geospatial Data and Maps"
author: [Your name here]
date: today
format:
  html:
    theme: cosmo
    toc: true
    toc-location: left
    toc-depth: 2
    highlight-style: github
    code-copy: true
    embed-resources: true
    df-print: paged
    fig-align: center
    fig-width: 8
    fig-height: 6
execute:
  message: false
editor: visual
---

*Note: The header at the top of this file has a bunch of settings to make your rendered html look nice. Don't worry about it (just add your name)!*

## Instructions

Welcome to your third lab assignment! It's time to make some beautiful maps on your own. Please read the following instructions before you begin.

For your lab assignments, you may use AI to help you code. You will be required to explicitly fill out the **SPARCK** framework for each question. You may not use AI to write the non-coding parts of the framework, although you may consult it for assistance.

As you write code, think about what we've learned in class so far, and especially what we learned in the Geospatial Data and Maps tutorial. You don't need to exclusively use functions we used in class, but they should serve as a reminder of the types of things you might wish to do. Except where noted, a version of everything you need to do can be found in our tutorials.

You should guide me through the answer the questions. This means you shouldn't just copy and paste code from Gemini and be done with it; your **SPARCK** responses should guide me through your thought process and analysis. You might also wish to spread your code across several different chunks so you can display output along the way if you think that makes it easier to understand.

Remember that you must render your Quarto document into an html file. This html is what you should hand in on Canvas. If you encounter errors, use Gemini to help you troubleshoot!

**Make sure you put this Quarto file in your Week 5 folder, and then open the file from that folder so that R's working directory is your Week 5 folder.**

**S: Set up** (What is your end goal?)

**P: Pseudocode** (What are the steps?)

**A: AI** (What are your AI prompts?)

**R: Run** (Run it!)

**C: Check** (Did your code work?)

**K: Knowledge** (What does your code mean?)

### Map-specific instructions

For all maps you make, they should look good. This means they have clear labels (including a title and a legend title that a normal human can understand), pretty colors, and no unnecessary axes or gridlines. Essentially, if you were giving a talk on this topic, your map should look like it belongs in your presentation.

## Question 0: The data

For this homework, you will be exploring **access to fresh food** in New York State, using a dataset of farmers' markets from New York State's open data portal (<https://data.ny.gov/>). The dataset comes from the New York State Department of Agriculture and Markets, and contains the name, location, and hours of every community farmers' market in the state. I have provided the dataset for you on our [course website](https://psyc1495f26.netlify.app/lab_tutorials). You will need to download the data and put it in your R Project folder. You can learn more about the dataset, including what every column means, [here](https://data.ny.gov/d/qq4h-8p86).

Besides each market's location, the dataset has several columns that tell us **who can use the market, and when**. Some that you might find interesting:

- `SNAP`: Does the market accept SNAP? (SNAP, the Supplemental Nutrition Assistance Program, sometimes called "food stamps," is the federal program that helps people with low incomes buy food.)

- `WIC VF`: Does the market accept WIC benefits for fruits and vegetables? (WIC is a nutrition program for pregnant people, new parents, and young children with low incomes.)

- `FCC Issued`: Does the market give out "FreshConnect Checks," which give SNAP shoppers an extra \$2 for every \$5 they spend?

- `FMNP`: Is the market part of the Farmers Market Nutrition Program, which gives coupons for fresh produce to seniors and WIC families?

- `Operating Months`: What times of year is the market open? (E.g., `YR` means year-round. See the link above for what the other codes mean.)

A farmers' market isn't really accessible to everyone if it doesn't accept the benefits that people with low incomes rely on, or if it's only open a few months a year. For this homework, **you get to decide which aspects of access you want to explore.** Throughout the homework, choose the variables and the places that *you* think tell the most interesting story. There's no single right answer, but you should explain your choices.

Load the packages you'll need, and load in the data. Take a look at it before you get started. Which variables do you think will be most interesting to map? Is there anything surprising about any of them? (Hint: Count up the values in some of the columns.)

```{r}

```

**What did you notice when you explored the data? Which variables do you want to focus on, and why?**

## Question 1: Mapping markets

Make a map that shows **where farmers' markets are**, with each market as a point. Use color (or another visual feature) to show something about each market that you find interesting (i.e. the columns I list out above).

You get to choose what area your map covers: the whole state, a region of the state, a single county, or New York City. You'll need to download boundaries from `tigris` to go underneath your points. These could be counties, but they don't have to be. Remember all of the different kinds of boundaries that `tigris` can download!

**S:**

**P:**

**A:**

**R:**

```{r}

```

(You may insert as many code chunks as you'd like. You can do so by going to Insert \> Executable Cell \> R in the toolbar above.)

**C:**

**K:**

**Explain what your map shows. Why did you choose this area and this variable?**

## Question 2: Comparing counties

Make a choropleth map that compares **counties** in New York State on some measure of farmers' market access that you find interesting. For example, you might count up all of the markets in each county, or only the markets that have a certain feature. (Hint: You'll need to summarize the markets in each county, and then join your summary to county boundaries from `tigris`. Think about which columns you should use to join them.)

**S:**

**P:**

**A:**

**R:**

```{r}

```

(You may insert as many code chunks as you'd like. You can do so by going to Insert \> Executable Cell \> R in the toolbar above.)

**C:**

**K:**

**Explain what your map shows. Which counties stand out, and why do you think that is?**

## Question 3: Counts vs. rates

In the tutorial, we learned that maps of **counts** can be misleading, because bigger places have more of almost everything. Make a second choropleth map that shows a **rate**: some count divided by a measure of size.

You get to decide what to divide by, but you should think about which measure of size makes the most sense for your question. Some options:

- **Population** (e.g., markets per 100,000 residents). The `usmap` package has a dataset with the population of each county.

- **Land area** (e.g., markets per 100 square miles). Remember the `ALAND` column in `tigris` data!

- **The total number of markets** (e.g., the *percentage* of markets in each county that accept SNAP).

Your map can be a rate version of your map from Question 2, or it can show something new.

**S:**

**P:**

**A:**

**R:**

```{r}

```

(You may insert as many code chunks as you'd like. You can do so by going to Insert \> Executable Cell \> R in the toolbar above.)

**C:**

**K:**

**Explain what your map shows. Why did you choose this measure of size? How does this map change (or add to) the story from Question 2?**

**Looking at all three of your maps, what is one thing that this data *can't* tell us about access to fresh food in New York? What other data would you want to answer that question?**
