library(magrittr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readr)
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(leaflet)
library(ggplot2)
library(sf)
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.1
## ✔ stringr 1.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ tidyr::extract() masks magrittr::extract()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ purrr::set_names() masks magrittr::set_names()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
df <- read_csv("Downloads/StructureMovementPermits_csv.csv")
## Rows: 1718 Columns: 66
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (31): Permit Type, Permit Type Desc, Permit Num, Permit Class Mapped, P...
## dbl (20): Total Existing Bldg SQFT, Total Job Valuation, Number Of Floors, ...
## lgl (12): Total New Add SQFT, Building Valuation, Building Valuation Remode...
## date (3): Applied Date, Issued Date, Completed Date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
n_distinct(df$`Original Address 1`)
## [1] 1551
df <- df[order(df[["Issued Date"]], decreasing = TRUE), ]
df <- df[!duplicated(df$`Original Address 1`), ]
df <- df[!grepl("ADU", df$Description),]
df <- filter(df, `Issued Date` > '2004-01-01')
This is the total number of permits issued (1548).
nrow(df)
## [1] 804
This is the # of permits by year
df %>%
mutate(year = format(`Issued Date`, "%Y")) %>%
group_by(year) %>%
summarise(count = n_distinct(`Original Address 1`))
This is the # of permits by year and by Zip Code, in order of frequency
cross <- df %>%
mutate(year = format(`Issued Date`, "%Y")) %>%
group_by(year, `Original Zip`) %>%
summarise(count = n_distinct(`Original Address 1`))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
cross[order(-cross$count),]
This is the # of permits by Zip Code, in order of frequency
zip <- df %>%
group_by(`Original Zip`) %>%
summarise(count = n_distinct(`Original Address 1`))
zip[order(-zip$count),]
This is the # of permits by Council District, in order of frequency
council <- df %>%
group_by(`Council District`) %>%
summarise(count = n_distinct(`Original Address 1`))
council[order(-council$count),]
This is the # of permits by Contractor, in order of frequency
contractor <- df %>%
group_by(`Contractor Company Name`) %>%
summarise(count = n_distinct(`Original Address 1`))
contractor[order(-contractor$count),]
Creating a new column of complete addresses
df$Combined<-paste(df$`Original Address 1`,df$`Original City`,sep=",")
df$Combined <- paste(df$Combined, df$`Original State`,sep=",")
df$Combined <- paste(df$Combined, df$`Original Zip`,sep=",")
Map of Different Addresses
library(ggmap)
## ℹ Google's Terms of Service: <https://mapsplatform.google.com>
## Stadia Maps' Terms of Service: <https://stadiamaps.com/terms-of-service/>
## OpenStreetMap's Tile Usage Policy: <https://operations.osmfoundation.org/policies/tiles/>
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
##
## Attaching package: 'ggmap'
##
##
## The following object is masked from 'package:magrittr':
##
## inset
library(tidygeocoder)
##
## Attaching package: 'tidygeocoder'
##
## The following object is masked from 'package:ggmap':
##
## geocode
library(mapview)
AddressFrequency <- function(addresses){
tab <- table(addresses)
unique.points <- data.frame(address=names(tab), frequency = c(tab))
rownames(unique.points) <- NULL
unique.points
}
freq <- AddressFrequency(df$Combined)
freq <- cbind(freq, geocode(freq, address = address))
## Passing 804 addresses to the Nominatim single address geocoder
## Query completed in: 818.1 seconds
newfreq <- na.omit(freq)
mapview(newfreq, xcol = "long", ycol = "lat", crs = 4269, grid = FALSE)