---
title: 'Homework #5'
author: "Your Name"
date: "11/20/2024"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Liquor Sales in Iowa

This dataset contains the spirits purchase information of Iowa Class “E” liquor licensees by product and date of purchase from January 1, 2017 to current. The dataset can be used to analyze total spirits sales in Iowa of individual products at the store level.

For all of the questions use functionality from the  `tidyverse` whenever possible.

1. Download the RMarkdown file with these homework instructions to use as a template for your work.
Make sure to replace "Your Name" in the YAML with your name.
2. The code below downloads the data from the Iowa Portal and saves a local copy to your machine. The first time you run this code, make sure you have a good internet connection and enough space on your machine (~50 MB). If the local copy exists, re-knitting the file will load the (binary) file from disk and be much faster. 
```{r, cache=TRUE}
if (!file.exists("ames-liquor.rds")) {
  url <- "https://github.com/ds202-at-ISU/materials/blob/master/03_tidyverse/data/ames-liquor.rds?raw=TRUE"
  download.file(url, "ames-liquor.rds", mode="wb")
}
data <- readRDS("ames-liquor.rds")
```
3. Quick fact overview (2 pts):

  - how many observations are in  `data`?
  - how many different cities are in the data? (Variable `City`, careful, trick question!)
  - different stores: how many different stores are in the data? Check first with `Store Name`, then with `Store Number`. Discuss differences (give an example), and then answer the question of how many different stores are in the data set.
  
3. Data cleaning (3 pts): 
  - extract geographic latitude and longitude from the variable `Store Location`
  - check variable types. Pick five variables that need to be converted to a different type and fix those. 
  - use the package `lubridate` to convert the `Date` variable to a date. Then extract year, month and day from the variable `Date`
4. First overview: (2 pts)
  - Plot a scatterplot of lat and long of store locations. 
  - Provide a visual breakdown of the liquor category (by `Category Name`). Include volume sold in the breakdown. Make sure that all labels are readable.
5. (3 pts) Find the daily liquor sales in Ames in 2021: summarize number of sales, volume of liquor sold and amount of money spent. 
Plot volume sold by day (use a scatterplot of volume by day and facet by month). Describe any patterns.
Find the dates for ISU football home games in Fall 2021. Can you see a pattern? Describe your finding.


Note: your submission is supposed to be fully reproducible (1 pts), i.e. the TA and I will 'knit' your submission in RStudio. 


For the submission: submit your solution in an R Markdown file and (just for insurance) submit the corresponding html (or Word) file with it. 
