---
title: "Lab 02 - Identifying Groups"
author: "Your Name"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
html_document:
df_print: paged
theme: cerulean
highlight: haddock
self_contained: true
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE,
message = FALSE,
warning = FALSE,
fig.width = 10,
fig.height = 6)
```
# Data
The following report identifies specific tax parcels in Downtown Syracuse, New York (USA).
View the dataset documentation here: [Syracuse, NY Tax Parcel Data](https://ds4ps.github.io/Data-Science-Class/DATA/syr_parcels.html).
## Required Packages
The following packages are required for this report and loaded with `library()`.
```{r}
library(sp)
library(rgdal)
library(geojsonio) # Load required libraries
```
## Import Spatial Polygons
We read in spatial polygons (`"sp"`) with function `geojson_read()` to map
tax parcel shapes in Syracuse's Downtown area.
```{r cache = TRUE}
url <- paste0("https://raw.githubusercontent.com/DS4PS/Data",
"-Science-Class/master/DATA/downtown-syr.geojson")
downtown <- geojson_read(url, what = "sp") # Load parcel data
plot(downtown,
border = "gray60",
col = "gray80") # Visualize parcels
```
# Example Solutions
The following examples demonstrate how to use conditions to identify specific parcels.
### Example: Tax Parcel Acres
Parcels with more than one acre are determined with variable `acres` and condition `> 1`.
* Each value in variable `acres` is tested as greater than one, or `> 1`
* Values in `acres` greater than one become `TRUE`, otherwise `FALSE`
* All `TRUE` and `FALSE` values are stored in object `these`
```{r}
result <- downtown$acres > 1 # Each value in 'acres' is tested
```
All `TRUE` and `FALSE` values, for each parcel, are converted into colors.
```{r}
group.colors <- ifelse(test = result, # 'test =' accepts TRUE or FALSE values
yes = "firebrick", # 'yes =' converts values that are TRUE
no = "gray80") # 'no =' converts values that are FALSE
```
All tax parcels in `downtown` are mapped with `plot()`. Each parcel has one of
two colors per the above code.
```{r}
plot(downtown, # Plots object 'downtown'
border = NA,
col = group.colors) # Red when TRUE; gray when FALSE
```
### Example: Parcels with Single Families
Use variable `landuse` to determine how a tax parcel is used. Determine all
possible values with `unique()`.
```{r}
unique(downtown$landuse) # All unique values in 'landuse'
```
One of the values in `landuse` is "Single Family". Therefore, the test is
whether or not `landuse` is exactly equal to "Single Family".
```{r}
result <- downtown$landuse == "Single Family" # Test if 'landuse' is "Single Family"
group.colors <- ifelse(test = result, # Provide TRUE or FALSE test results
yes = "firebrick", # If TRUE, make "firebrick"
no = "gray80") # If FALSE, make "gray80"
plot(downtown,
border = NA,
col = group.colors) # Plot with respective colors
```
# Questions & Solutions
The following questions ask you to map your results, write your answer, or both.
The first question has been completed for you.
## Question 1: Vacant Lots
**Question:** *Where are the majority of vacant lots located in the*
*downtown? Map your results.*
**Note:** *This solution has been provided for you.*
```{r}
unique(downtown$landuse) # Print unique values in 'landuse'
```
Now, we create our test statement, `== "Vacant Land"`, and store the results in `result`.
```{r}
result <- downtown$landuse == "Vacant Land"
group.colors <- ifelse(test = result,
yes = "firebrick",
no = "gray80")
plot(downtown,
border = NA,
col = group.colors)
```
## Question 2: Parking Lots
**Question:** *How many parking lots are in downtown Syracuse? Map your results.*
**Answer:** There are **[x]** parking lots in downtown Syracuse.
```{r}
# Use function: 'sum()'
# Use variable: 'landuse'
# Assign test (logical) output to object 'result' by replacing 'FALSE'
result <- FALSE
group.colors <- ifelse(test = result,
yes = "firebrick",
no = "gray80")
plot(downtown,
border = NA,
col = group.colors)
```
## Question 3: New Construction
**Question:** *Where is new construction located in the city?. Map your results.*
**Note:** You may use `>=` (greater than or equal) or `>` (greater than) 1980.
```{r}
# Use variable: 'yearbuilt'
# Find the number of buildings constructed either after or during and after than 1980
# Assign test (logical) output to object 'result' by replacing 'FALSE'
result <- FALSE
group.colors <- ifelse(test = result,
yes = "firebrick",
no = "gray80")
plot(downtown,
border = NA,
col = group.colors)
```
**Question:** *What proportion of commercial properties are built since 1980?*
**Answer:** **[X]%** of commercial properties were built since 1980.
```{r}
# Use variable: 'landuse'
# Use variable: 'yearbuilt'
# Count only commercial properties with buildings constructed during or later than 1980
```
## Question 4: Parcels Valued Over $10M
**Question:** *How many parcels have assessed values over $10 million? Map your results.*
**Answer:** **[X]** parcels have assessed values over $10 M.
```{r}
# Use function: 'sum()'
# Use variable: 'assessedval'
# Assign test (logical) output to object 'result' by replacing 'FALSE'
result <- FALSE
group.colors <- ifelse(test = result,
yes = "firebrick",
no = "gray80")
plot(downtown,
border = NA,
col = group.colors)
```
## Question 5: Total Tax Delinquent Parcels
**Question:** *How many properties are delinquent on taxes? Map your results.*
**Answer:** **[X]** properties are delinquent on taxes.
```{r}
# Use function: 'sum()'
# Use variable: 'amtdelinqt'
# Assign test (logical) output to object 'result' by replacing 'FALSE'
result <- FALSE
group.colors <- ifelse(test = result,
yes = "firebrick",
no = "gray80")
plot(downtown,
border = NA,
col = group.colors)
```
## Question 6: Tax Delinquent Parcels
**Question:** *What proportion of parcels have delinquent tax payments owed?*
**Answer:** **[X%]** of parcels have delinquent tax payments owed.
```{r}
# Use function: 'mean()'
# Use variable: 'amtdelinqt'
```
## Question 7: Tax Delinquent Commercial Properties
**Question I:** *What proportion of commercial properties are delinquent on taxes?*
**Question II:** *What proportion of delinquent tax bills are owed by commercial parcels?*
**Answer I:** **[X]%** of commercial properties are delinquent on taxes.
**Answer II:** **[X]%** of delinquent tax dollars are owed by commercial parcels.
```{r}
# Use function: 'mean()'
# Use variable: 'amtdelinqt'
# Use variable: 'landuse'
# The first answer is tax-delinquent commercial properties over all commercial properties
# The second answer is the tax dollars owed by commercial properties (a subset) over all tax dollars owed
```
## Question 8: Tax Delinquent Parcels by Land Use
**Question:** *How many of each land use type are delinquent on taxes? Print a table of your results.*
```{r}
# Use function: 'table()'
# Use variable: 'amtdelinqt'
# Use variable: 'landuse'
```