library
library(acs) # access acs survey data
library(tidyverse) # data manupliation
library(tidycensus) # access census data
library(ggplot2)
library(ggmap)
library(maptools)
library(ggthemes)
library(rgeos)
library(broom)
library(dplyr)
library(plyr)
library(grid)
library(gridExtra)
library(reshape2)
library(scales)
library(tigris)
library(sf)
Linking to GEOS 3.8.1, GDAL 2.4.4, PROJ 7.0.0
library(rgdal)
rgdal: version: 1.4-8, (SVN revision 845)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.4.2, released 2019/06/28
Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/gdal
GDAL binary built with GEOS: FALSE
Loaded PROJ.4 runtime: Rel. 5.2.0, September 15th, 2018, [PJ_VERSION: 520]
Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
Linking to sp version: 1.3-2
library(leaflet)
library(sp)
library(devtools)
library(censusapi)
Attaching package: ‘censusapi’
The following object is masked from ‘package:methods’:
getFunction
library(XML)
library(RCurl)
Attaching package: ‘RCurl’
The following object is masked from ‘package:tidyr’:
complete
register_google(key = "AIzaSyA2ssODSDKBAXe5MOgxz6rL_JfnN7JTX30")
# Next, we’re going to define two themes that will tell ggplot how to construct both maps and plots. Defining our themes up front ensures that we don’t have to repeat this code over and again for every plot we generate below
plotTheme <- function(base_size = 12) {
theme(
text = element_text( color = "black"),
plot.title = element_text(size = 18,colour = "black"),
plot.subtitle = element_text(face="italic"),
plot.caption = element_text(hjust=0),
axis.ticks = element_blank(),
panel.background = element_blank(),
panel.grid.major = element_line("grey80", size = 0.1),
panel.grid.minor = element_blank(),
strip.background = element_rect(fill = "grey80", color = "white"),
strip.text = element_text(size=12),
axis.title = element_text(size=8),
axis.text = element_text(size=8),
axis.title.x = element_text(hjust=1),
axis.title.y = element_text(hjust=1),
plot.background = element_blank(),
legend.background = element_blank(),
legend.title = element_text(colour = "black", face = "italic"),
legend.text = element_text(colour = "black", face = "italic"))
}
# And another that we will use for maps
mapTheme <- function(base_size = 12) {
theme(
text = element_text( color = "black"),
plot.title = element_text(size = 18,colour = "black"),
plot.subtitle=element_text(face="italic"),
plot.caption=element_text(hjust=0),
axis.ticks = element_blank(),
panel.background = element_blank(),
panel.grid.major = element_line("grey80", size = 0.1),
strip.text = element_text(size=12),
axis.title = element_blank(),
axis.text = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.minor = element_blank(),
strip.background = element_rect(fill = "grey80", color = "white"),
plot.background = element_blank(),
legend.background = element_blank(),
legend.title = element_text(colour = "black", face = "italic"),
legend.text = element_text(colour = "black", face = "italic"))
}
# Define some palettes
palette_9_colors <- c("#0DA3A0","#2999A9","#458FB2","#6285BB","#7E7CC4","#9A72CD","#B768D6","#D35EDF","#F055E9")
palette_8_colors <- c("#0DA3A0","#2D97AA","#4D8CB4","#6E81BF","#8E76C9","#AF6BD4","#CF60DE","#F055E9")
palette_7_colors <- c("#2D97AA","#4D8CB4","#6E81BF","#8E76C9","#AF6BD4","#CF60DE","#F055E9")
palette_1_colors <- c("#0DA3A0")
Get Boston Rental Data as a table dataframe
BR_2_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1361188921.txt")
BR_3_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1363604521.txt")
BR_4_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1366282922.txt")
BR_5_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1368874922.txt")
BR_6_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1371553321.txt")
BR_7_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1374145322.txt")
BR_8_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1376823721.txt")
BR_9_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1379502122.txt")
BR_10_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1382094122.txt")
BR_11_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1384776122.txt")
BR_11_21_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1385024431.txt")
BR_12_18_2013 <-read.table("https://www.jefftk.com/apartment_prices/apts-1387368122.txt")
BR_1_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1390046522.txt")
BR_2_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1392724922.txt")
BR_3_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1395140522.txt")
BR_4_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1397818922.txt")
BR_5_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1400410922.txt")
BR_6_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1403089321.txt")
BR_7_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1405681321.txt")
BR_8_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1408359722.txt")
BR_9_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1411038121.txt")
BR_10_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1413597722.txt")
BR_11_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1416276121.txt")
BR_12_18_2014 <-read.table("https://www.jefftk.com/apartment_prices/apts-1418868122.txt")
BR_1_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1421546523.txt")
BR_2_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1424224922.txt")
BR_3_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1426644122.txt")
BR_4_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1429322522.txt")
BR_5_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1431914522.txt")
BR_6_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1434592921.txt")
BR_7_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1437184922.txt")
BR_8_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1439863322.txt")
BR_9_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1442541722.txt")
BR_10_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1445133723.txt")
BR_11_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1447812123.txt")
BR_12_18_2015 <-read.table("https://www.jefftk.com/apartment_prices/apts-1450404122.txt")
BR_1_18_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1453082522.txt")
BR_2_18_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1455760922.txt")
BR_3_18_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1458266521.txt")
BR_4_18_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1460944923.txt")
BR_5_18_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1463536922.txt")
BR_6_18_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1466215323.txt")
BR_7_18_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1468807322.txt")
BR_8_18_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1471485722.txt")
BR_9_18_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1474164121.txt")
BR_10_28_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1477662757.txt")
BR_11_18_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1479477370.txt")
BR_12_19_2016 <-read.table("https://www.jefftk.com/apartment_prices/apts-1482155325.txt")
BR_1_18_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1484743042.txt")
BR_2_19_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1487511252.txt")
BR_3_19_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1489951548.txt")
BR_4_18_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1492528051.txt")
BR_5_18_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1495128565.txt")
BR_6_18_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1497785436.txt")
BR_7_18_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1500389951.txt")
BR_8_18_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1503056501.txt")
BR_9_19_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1505830448.txt")
BR_10_18_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1508347437.txt")
BR_11_18_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1511025718.txt")
BR_12_18_2017 <-read.table("https://www.jefftk.com/apartment_prices/apts-1513607533.txt")
BR_1_18_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1516280053.txt")
BR_2_21_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1519173184.txt")
BR_3_18_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1521392156.txt")
BR_4_18_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1524056383.txt")
BR_4_18_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1524059974.txt")
BR_5_18_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1526663745.txt")
BR_7_18_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1531942677.txt")
BR_8_18_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1534594761.txt")
BR_9_18_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1537269695.txt")
BR_10_18_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1539895062.txt")
BR_11_19_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1542637382.txt")
BR_12_18_2018 <-read.table("https://www.jefftk.com/apartment_prices/apts-1545151888.txt")
BR_1_27_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1548600831.txt")
BR_2_18_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1550519514.txt")
BR_3_18_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1552916163.txt")
BR_4_18_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1555593780.txt")
BR_5_20_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1558364572.txt")
BR_6_18_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1560875990.txt")
BR_8_3_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1564836478.txt")
BR_8_18_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1566158813.txt")
BR_9_18_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1568827984.txt")
BR_10_20_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1571532666.txt")
BR_11_18_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1574092365.txt")
BR_12_18_2019 <-read.table("https://www.jefftk.com/apartment_prices/apts-1576687349.txt")
BR_1_18_2020 <-read.table("https://www.jefftk.com/apartment_prices/apts-1579389225.txt")
BR_2_18_2020 <-read.table("https://www.jefftk.com/apartment_prices/apts-1582039669.txt")
BR_3_20_2020 <-read.table("https://www.jefftk.com/apartment_prices/apts-1584708383.txt")
Add Year
BR_2_18_2013$Year <-"2013"
BR_3_18_2013$Year <-"2013"
BR_4_18_2013$Year <-"2013"
BR_5_18_2013$Year <-"2013"
BR_6_18_2013$Year <-"2013"
BR_7_18_2013$Year <-"2013"
BR_8_18_2013$Year <-"2013"
BR_9_18_2013$Year <-"2013"
BR_10_18_2013$Year <-"2013"
BR_11_18_2013$Year <-"2013"
BR_11_21_2013$Year <-"2013"
BR_12_18_2013$Year <-"2013"
BR_1_18_2014$Year <-"2014"
BR_2_18_2014$Year <-"2014"
BR_3_18_2014$Year <-"2014"
BR_4_18_2014$Year <-"2014"
BR_5_18_2014$Year <-"2014"
BR_6_18_2014$Year <-"2014"
BR_7_18_2014$Year <-"2014"
BR_8_18_2014$Year <-"2014"
BR_9_18_2014$Year <-"2014"
BR_10_18_2014$Year <-"2014"
BR_11_18_2014$Year <-"2014"
BR_12_18_2014$Year <-"2014"
BR_1_18_2015$Year <-"2015"
BR_2_18_2015$Year <-"2015"
BR_3_18_2015$Year <-"2015"
BR_4_18_2015$Year <-"2015"
BR_5_18_2015$Year <-"2015"
BR_6_18_2015$Year <-"2015"
BR_7_18_2015$Year <-"2015"
BR_8_18_2015$Year <-"2015"
BR_9_18_2015$Year <-"2015"
BR_10_18_2015$Year <-"2015"
BR_11_18_2015$Year <-"2015"
BR_12_18_2015$Year <-"2015"
BR_1_18_2016$Year <-"2016"
BR_2_18_2016$Year <-"2016"
BR_3_18_2016$Year <-"2016"
BR_4_18_2016$Year <-"2016"
BR_5_18_2016$Year <-"2016"
BR_6_18_2016$Year <-"2016"
BR_7_18_2016$Year <-"2016"
BR_8_18_2016$Year <-"2016"
BR_9_18_2016$Year <-"2016"
BR_10_28_2016$Year <-"2016"
BR_11_18_2016$Year <-"2016"
BR_12_19_2016$Year <-"2016"
BR_1_18_2017$Year <-"2017"
BR_2_19_2017$Year <-"2017"
BR_3_19_2017$Year <-"2017"
BR_4_18_2017$Year <-"2017"
BR_5_18_2017$Year <-"2017"
BR_6_18_2017$Year <-"2017"
BR_7_18_2017$Year <-"2017"
BR_8_18_2017$Year <-"2017"
BR_9_19_2017$Year <-"2017"
BR_10_18_2017$Year <-"2017"
BR_11_18_2017$Year <-"2017"
BR_12_18_2017$Year <-"2017"
BR_1_18_2018$Year <-"2018"
BR_2_21_2018$Year <-"2018"
BR_3_18_2018$Year <-"2018"
BR_4_18_2018$Year <-"2018"
BR_4_18_2018$Year <-"2018"
BR_5_18_2018$Year <-"2018"
BR_7_18_2018$Year <-"2018"
BR_8_18_2018$Year <-"2018"
BR_9_18_2018$Year <-"2018"
BR_10_18_2018$Year <-"2018"
BR_11_19_2018$Year <-"2018"
BR_12_18_2018$Year <-"2018"
BR_1_27_2019$Year <-"2019"
BR_2_18_2019$Year <-"2019"
BR_3_18_2019$Year <-"2019"
BR_4_18_2019$Year <-"2019"
BR_5_20_2019$Year <-"2019"
BR_6_18_2019$Year <-"2019"
BR_8_3_2019$Year <-"2019"
BR_8_18_2019$Year <-"2019"
BR_9_18_2019$Year <-"2019"
BR_10_20_2019$Year <-"2019"
BR_11_18_2019$Year <-"2019"
BR_12_18_2019$Year <-"2019"
BR_1_18_2020$Year <-"2020"
BR_2_18_2020$Year <-"2020"
BR_3_20_2020$Year <-"2020"
Add Month
BR_2_18_2013$Month <-"Feb"
BR_3_18_2013$Month <-"Mar"
BR_4_18_2013$Month <-"Apr"
BR_5_18_2013$Month <-"May"
BR_6_18_2013$Month <-"Jun"
BR_7_18_2013$Month <-"Jul"
BR_8_18_2013$Month <-"Aug"
BR_9_18_2013$Month <-"Sep"
BR_10_18_2013$Month <-"Oct"
BR_11_18_2013$Month <-"Nov"
BR_11_21_2013$Month <-"Nov"
BR_12_18_2013$Month <-"Dec"
BR_1_18_2014$Month <-"Jan"
BR_2_18_2014$Month <-"Feb"
BR_3_18_2014$Month <-"Mar"
BR_4_18_2014$Month <-"Apr"
BR_5_18_2014$Month <-"May"
BR_6_18_2014$Month <-"Jun"
BR_7_18_2014$Month <-"Jul"
BR_8_18_2014$Month <-"Aug"
BR_9_18_2014$Month <-"Sep"
BR_10_18_2014$Month <-"Oct"
BR_11_18_2014$Month <-"Nov"
BR_12_18_2014$Month <-"Dec"
BR_1_18_2015$Month <-"Jan"
BR_2_18_2015$Month <-"Feb"
BR_3_18_2015$Month <-"Mar"
BR_4_18_2015$Month <-"Apr"
BR_5_18_2015$Month <-"May"
BR_6_18_2015$Month <-"Jun"
BR_7_18_2015$Month <-"Jul"
BR_8_18_2015$Month <-"Aug"
BR_9_18_2015$Month <-"Sep"
BR_10_18_2015$Month <-"Oct"
BR_11_18_2015$Month <-"Nov"
BR_12_18_2015$Month <-"Dec"
BR_1_18_2016$Month <-"Jan"
BR_2_18_2016$Month <-"Feb"
BR_3_18_2016$Month <-"Mar"
BR_4_18_2016$Month <-"Apr"
BR_5_18_2016$Month <-"May"
BR_6_18_2016$Month <-"Jun"
BR_7_18_2016$Month <-"Jul"
BR_8_18_2016$Month <-"Aug"
BR_9_18_2016$Month <-"Sep"
BR_10_28_2016$Month <-"Oct"
BR_11_18_2016$Month <-"Nov"
BR_12_19_2016$Month <-"Dec"
BR_1_18_2017$Month <-"Jan"
BR_2_19_2017$Month <-"Feb"
BR_3_19_2017$Month <-"Mar"
BR_4_18_2017$Month <-"Apr"
BR_5_18_2017$Month <-"May"
BR_6_18_2017$Month <-"Jun"
BR_7_18_2017$Month <-"Jul"
BR_8_18_2017$Month <-"Aug"
BR_9_19_2017$Month <-"Sep"
BR_10_18_2017$Month <-"Oct"
BR_11_18_2017$Month <-"Nov"
BR_12_18_2017$Month <-"Dec"
BR_1_18_2018$Month <-"Jan"
BR_2_21_2018$Month <-"Feb"
BR_3_18_2018$Month <-"Mar"
BR_4_18_2018$Month <-"Apr"
BR_4_18_2018$Month <-"Apr"
BR_5_18_2018$Month <-"May"
BR_7_18_2018$Month <-"Jul"
BR_8_18_2018$Month <-"Aug"
BR_9_18_2018$Month <-"Sep"
BR_10_18_2018$Month <-"Oct"
BR_11_19_2018$Month <-"Nov"
BR_12_18_2018$Month <-"Dec"
BR_1_27_2019$Month <-"Jan"
BR_2_18_2019$Month <-"Feb"
BR_3_18_2019$Month <-"Mar"
BR_4_18_2019$Month <-"Apr"
BR_5_20_2019$Month <-"May"
BR_6_18_2019$Month <-"Jun"
BR_8_3_2019$Month <-"Aug"
BR_8_18_2019$Month <-"Aug"
BR_9_18_2019$Month <-"Sep"
BR_10_20_2019$Month <-"Oct"
BR_11_18_2019$Month <-"Nov"
BR_12_18_2019$Month <-"Dec"
BR_1_18_2020$Month <-"Jan"
BR_2_18_2020$Month <-"Feb"
BR_3_20_2020$Month <-"Mar"
Merge by Year
# 2013
BR_2013 <- rbind(BR_2_18_2013,
BR_3_18_2013,
BR_4_18_2013,
BR_5_18_2013,
BR_6_18_2013,
BR_7_18_2013,
BR_8_18_2013,
BR_9_18_2013,
BR_10_18_2013,
BR_11_18_2013,
BR_11_21_2013,
BR_12_18_2013)
# 2014
BR_2014 <- rbind(BR_1_18_2014,
BR_2_18_2014,
BR_3_18_2014,
BR_4_18_2014,
BR_5_18_2014,
BR_6_18_2014,
BR_7_18_2014,
BR_8_18_2014,
BR_9_18_2014,
BR_10_18_2014,
BR_11_18_2014,
BR_12_18_2014)
# 2015
BR_2015 <- rbind(BR_1_18_2015,
BR_2_18_2015,
BR_3_18_2015,
BR_4_18_2015,
BR_5_18_2015,
BR_6_18_2015,
BR_7_18_2015,
BR_8_18_2015,
BR_9_18_2015,
BR_10_18_2015,
BR_11_18_2015,
BR_12_18_2015)
# 2016
BR_2016 <- rbind(BR_1_18_2016,
BR_2_18_2016,
BR_3_18_2016,
BR_4_18_2016,
BR_5_18_2016,
BR_6_18_2016,
BR_7_18_2016,
BR_8_18_2016,
BR_9_18_2016,
BR_10_28_2016,
BR_11_18_2016,
BR_12_19_2016)
# 2017
BR_2017 <- rbind(BR_1_18_2017,
BR_2_19_2017,
BR_3_19_2017,
BR_4_18_2017,
BR_5_18_2017,
BR_6_18_2017,
BR_7_18_2017,
BR_8_18_2017,
BR_9_19_2017,
BR_10_18_2017,
BR_11_18_2017,
BR_12_18_2017)
# 2018
BR_2018 <- rbind(BR_1_18_2018,
BR_2_21_2018,
BR_3_18_2018,
BR_4_18_2018,
BR_4_18_2018,
BR_5_18_2018,
BR_7_18_2018,
BR_8_18_2018,
BR_9_18_2018,
BR_10_18_2018,
BR_11_19_2018,
BR_12_18_2018)
# 2019
BR_2019 <- rbind(BR_1_27_2019,
BR_2_18_2019,
BR_3_18_2019,
BR_4_18_2019,
BR_5_20_2019,
BR_6_18_2019,
BR_8_3_2019,
BR_8_18_2019,
BR_9_18_2019,
BR_10_20_2019,
BR_11_18_2019,
BR_12_18_2019)
# 2020
BR_2020 <- rbind(BR_1_18_2020,
BR_2_18_2020,
BR_3_20_2020)
Update Column Names
# 2020
names(BR_2020)[1] <- "Rent"
names(BR_2020)[2] <- "Bedrooms"
names(BR_2020)[3] <- "ID"
names(BR_2020)[4] <- "Lon"
names(BR_2020)[5] <- "Lat"
# 2019
names(BR_2019)[1] <- "Rent"
names(BR_2019)[2] <- "Bedrooms"
names(BR_2019)[3] <- "ID"
names(BR_2019)[4] <- "Lon"
names(BR_2019)[5] <- "Lat"
# 2018
names(BR_2018)[1] <- "Rent"
names(BR_2018)[2] <- "Bedrooms"
names(BR_2018)[3] <- "ID"
names(BR_2018)[4] <- "Lon"
names(BR_2018)[5] <- "Lat"
# 2017
names(BR_2017)[1] <- "Rent"
names(BR_2017)[2] <- "Bedrooms"
names(BR_2017)[3] <- "ID"
names(BR_2017)[4] <- "Lon"
names(BR_2017)[5] <- "Lat"
# 2016
names(BR_2016)[1] <- "Rent"
names(BR_2016)[2] <- "Bedrooms"
names(BR_2016)[3] <- "ID"
names(BR_2016)[4] <- "Lon"
names(BR_2016)[5] <- "Lat"
# 2015
names(BR_2015)[1] <- "Rent"
names(BR_2015)[2] <- "Bedrooms"
names(BR_2015)[3] <- "ID"
names(BR_2015)[4] <- "Lon"
names(BR_2015)[5] <- "Lat"
# 2014
names(BR_2014)[1] <- "Rent"
names(BR_2014)[2] <- "Bedrooms"
names(BR_2014)[3] <- "ID"
names(BR_2014)[4] <- "Lon"
names(BR_2014)[5] <- "Lat"
# 2013
names(BR_2013)[1] <- "Rent"
names(BR_2013)[2] <- "Bedrooms"
names(BR_2013)[3] <- "ID"
names(BR_2013)[4] <- "Lon"
names(BR_2013)[5] <- "Lat"
Merge into one dataframe
Download data.frame
write.csv(BR_2013_2020, "BR_2013_2020.csv")
Distribution of Boston Rent Prices Nominal Prices (2013 - 2020)
rent_value_hist <- ggplot(BR_2013_2019, aes(Rent)) +
geom_histogram(fill=palette_1_colors) +
xlab("Rent Price($)") + ylab("Count") +
scale_fill_manual(values=palette_1_colors) +
plotTheme() +
labs(x="Rent Price($)", y="Count", title="Distribution of Boston Rent prices",
subtitle="Nominal prices (2013 - 2020)",
caption="Source: Padmapper UI\n@JeffKaufman")
# Plotting it:
rent_value_hist
It seems as though there may be some outliers. We’ll remove anything greater than 2.5 standard deviations from the mean.
check out the distribution of prices for each year using a violin plot
rent_value_violin <- ggplot(BR_13_29, aes(x=Year, y=Rent, fill=Year)) +
geom_violin(color = "grey50") +
xlab("Rent Price($)") + ylab("Count") +
scale_fill_manual(values=palette_7_colors) +
stat_summary(fun.y=mean, geom="point", size=2, colour="white") +
plotTheme() + theme(legend.position="none") +
scale_y_continuous(labels = comma) +
labs(x="Year",y="Rent Price($)",title="Distribution of Boston Rent prices",
subtitle="Nominal prices (2013 - 2019); Rent price means visualized as points",
caption="Source: Padmapper UI\n@JeffKaufman")
`fun.y` is deprecated. Use `fun` instead.
rent_value_violin
The white circles denote sale price means for each year.
Distribution of Northeastern Rent Prices
# Add Boston Shape file with names of neighborhoods
Boston_neighb <- readOGR("Boston_Neighborhoods",layer = "Boston_Neighborhoods")
bbox <- Boston_neighb@bbox
bos_bbox <- c(left = bbox[1, 1] - .01, bottom = bbox[2, 1] - .005,
right = bbox[1, 2] + .01, top = bbox[2, 2] + .005)
basemap <- get_stamenmap(
bbox = bos_bbox,
zoom = 12,
maptype = "toner-lite")
# Map it
bmMap <- ggmap(basemap) + mapTheme() +
labs(title="Boston basemap")
bmMap
Distribution of Boston Rent Prices
library(mapproj)
Loading required package: maps
Attaching package: ‘maps’
The following object is masked from ‘package:plyr’:
ozone
The following object is masked from ‘package:purrr’:
map
prices_mapped_by_year <- ggmap(basemap) +
geom_point(data = BR_13_19, aes(x = Lon, y = Lat, color = Rent),
size = .25, alpha = 0.6) +
facet_wrap(~Year, scales = "fixed", ncol = 4) +
coord_map() +
mapTheme() + theme(legend.position = c(.85, .25)) +
scale_color_gradientn("Rent Price",
colors = palette_8_colors,
labels = scales::dollar_format(prefix = "$")) +
labs(title="Distribution of Boston Rent prices",
subtitle="Nominal prices (2013 - 2019)",
caption="Source: Padmapper UI\n@JeffKaufman")
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
prices_mapped_by_year
prices_mapped_2013_2019 <- ggmap(basemap) +
geom_point(data = subset(BR_13_19, BR_13_19$Year == 2013 | BR_13_19$Year == 2019),
aes(x = Lon, y = Lat, color = Rent),
size = 1, alpha = 0.75) +
facet_wrap(~Year, scales = "fixed", ncol = 1) +
coord_map() +
mapTheme() +
scale_color_gradientn("Sale Price",
colors = palette_8_colors,
labels = scales::dollar_format(prefix = "$")) +
labs(title="Distribution of Boston Rent prices",
subtitle="Nominal prices (2013 & 2019)",
caption="Source: Padmapper UI\n@JeffKaufman")
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
prices_mapped_2013_2019
Merging Rent Data with Boston Neighbrohood Polygon
Neighborhood—Fenway
Neighborhood—Mission Hill
Neighborhood—Roxbury
Neighborhood—South End
Distribution of Rent prices around Northeastern University
Boston Summarization
Boston_Rents_summarized <- ddply(Boston_Rent_Data, c("Name","Year"), summarise,
medianRent = median(Rent),
rentCount = length(Year),
sdRent = sd(Rent),
minusSd = medianRent - sdRent,
plusSD = medianRent + sdRent,
.progress = "text")
|
| | 0%
|
|= | 1%
|
|== | 2%
|
|=== | 3%
|
|==== | 3%
|
|==== | 4%
|
|===== | 5%
|
|====== | 6%
|
|======= | 7%
|
|======== | 7%
|
|======== | 8%
|
|========= | 9%
|
|========== | 10%
|
|=========== | 10%
|
|=========== | 11%
|
|============ | 11%
|
|============ | 12%
|
|============= | 13%
|
|============== | 13%
|
|============== | 14%
|
|=============== | 14%
|
|=============== | 15%
|
|================ | 15%
|
|================ | 16%
|
|================= | 17%
|
|================== | 17%
|
|================== | 18%
|
|=================== | 18%
|
|=================== | 19%
|
|==================== | 19%
|
|===================== | 20%
|
|===================== | 21%
|
|====================== | 21%
|
|====================== | 22%
|
|======================= | 22%
|
|======================== | 23%
|
|========================= | 24%
|
|========================= | 25%
|
|========================== | 25%
|
|========================== | 26%
|
|=========================== | 26%
|
|============================ | 27%
|
|============================= | 28%
|
|============================= | 29%
|
|============================== | 29%
|
|=============================== | 30%
|
|================================ | 31%
|
|================================= | 32%
|
|================================== | 33%
|
|=================================== | 34%
|
|==================================== | 35%
|
|===================================== | 36%
|
|====================================== | 37%
|
|======================================= | 38%
|
|======================================== | 39%
|
|========================================= | 39%
|
|========================================= | 40%
|
|========================================== | 41%
|
|=========================================== | 42%
|
|============================================ | 42%
|
|============================================ | 43%
|
|============================================= | 43%
|
|============================================= | 44%
|
|============================================== | 45%
|
|=============================================== | 46%
|
|================================================ | 46%
|
|================================================ | 47%
|
|================================================= | 47%
|
|================================================= | 48%
|
|================================================== | 49%
|
|=================================================== | 49%
|
|=================================================== | 50%
|
|==================================================== | 50%
|
|==================================================== | 51%
|
|===================================================== | 51%
|
|====================================================== | 52%
|
|====================================================== | 53%
|
|======================================================= | 53%
|
|======================================================= | 54%
|
|======================================================== | 54%
|
|========================================================= | 55%
|
|========================================================== | 56%
|
|========================================================== | 57%
|
|=========================================================== | 57%
|
|=========================================================== | 58%
|
|============================================================ | 58%
|
|============================================================= | 59%
|
|============================================================== | 60%
|
|============================================================== | 61%
|
|=============================================================== | 61%
|
|================================================================ | 62%
|
|================================================================= | 63%
|
|================================================================== | 64%
|
|=================================================================== | 65%
|
|==================================================================== | 66%
|
|===================================================================== | 67%
|
|====================================================================== | 68%
|
|======================================================================= | 69%
|
|======================================================================== | 70%
|
|========================================================================= | 71%
|
|========================================================================== | 71%
|
|========================================================================== | 72%
|
|=========================================================================== | 73%
|
|============================================================================ | 74%
|
|============================================================================= | 74%
|
|============================================================================= | 75%
|
|============================================================================== | 75%
|
|============================================================================== | 76%
|
|=============================================================================== | 77%
|
|================================================================================ | 78%
|
|================================================================================= | 78%
|
|================================================================================= | 79%
|
|================================================================================== | 79%
|
|================================================================================== | 80%
|
|=================================================================================== | 81%
|
|==================================================================================== | 81%
|
|==================================================================================== | 82%
|
|===================================================================================== | 82%
|
|===================================================================================== | 83%
|
|====================================================================================== | 83%
|
|======================================================================================= | 84%
|
|======================================================================================= | 85%
|
|======================================================================================== | 85%
|
|======================================================================================== | 86%
|
|========================================================================================= | 86%
|
|========================================================================================= | 87%
|
|========================================================================================== | 87%
|
|=========================================================================================== | 88%
|
|=========================================================================================== | 89%
|
|============================================================================================ | 89%
|
|============================================================================================ | 90%
|
|============================================================================================= | 90%
|
|============================================================================================== | 91%
|
|=============================================================================================== | 92%
|
|=============================================================================================== | 93%
|
|================================================================================================ | 93%
|
|================================================================================================= | 94%
|
|================================================================================================== | 95%
|
|=================================================================================================== | 96%
|
|=================================================================================================== | 97%
|
|==================================================================================================== | 97%
|
|===================================================================================================== | 98%
|
|====================================================================================================== | 99%
|
|=======================================================================================================| 100%
yearly_rents <- ddply(Boston_Rents_summarized, ~Name, summarise,
avg.yearly.rent = mean(rentCount))
Boston_Rents_summarized <- left_join(Boston_Rents_summarized, yearly_rents, by = "Name")
medByYear <- dcast(Boston_Rents_summarized, Name ~ Year, value.var = "medianRent")
medByYear$pctChange <- (medByYear$`2019` - medByYear$`2013`) / medByYear$`2013`
Boston_Rents_summarized <- left_join(Boston_Rents_summarized, medByYear[,c("Name", "pctChange")],
by = "Name")
Boston_Rents_summarized
neighb.tidy <- tidy(Boston_neighb, region = c('Name'))
Ring Self-intersection at or near point -71.125747340000004 42.27233854SpP is invalid
Invalid objects found; consider using set_RGEOS_CheckValidity(2L)Unequal factor levels: coercing to characterbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorUnequal factor levels: coercing to characterbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vector
neighb.tidy$Name <- neighb.tidy$id
Boston_Rents_summarized <- join(Boston_Rents_summarized, neighb.tidy, by = "Name", match = "all")
Boston_Rents_summarized
NA
Northeastern Summeraization
Median Rent Price by Northeastern Neighborhood
neighb_map <- ggmap(basemap) +
geom_polygon(data = Northeastern_Rents_summarized_tidy,
aes(x = long, y = lat, group = group, fill = medianRent),
colour = "white", alpha = 0.75, size = 0.25) +
scale_fill_gradientn("Neighborhood \nMedian \nRent Price",
colors = palette_8_colors,
labels = scales::dollar_format(prefix = "$")) +
mapTheme() + theme(legend.position = c(.85, .25)) + coord_map() +
facet_wrap(~Year, nrow = 2) +
labs(title="Median rent price by neighborhood, Northeastern ",
subtitle="Nominal prices (2013 - 2019)",
caption="Source: Padmapper UI\n@JeffKaufman")
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
neighb_map
Percent Change in Rent
Time Sereis Plots
Boston_Rents_summarized
# Lets look at the top 8 most appreciating neighborhoods.
topPctChange <- unique(Boston_Rents_summarized$pctChange) %>% sort(decreasing = TRUE) %>% head(8)
# Well use these percentages to subset our neighborhoods data frame
bosForTimeSeries <- Boston_Rents_summarized[which(Boston_Rents_summarized$pctChange %in% topPctChange), ]
time.series <- ggplot(bosForTimeSeries, aes(x = Year, group=Name)) +
geom_line(aes(y = medianRent)) +
geom_ribbon(aes(ymin = minusSd, ymax = plusSD, fill = Name), alpha = 0.75) +
facet_wrap(~Name, scales = "fixed", nrow = 4) +
scale_y_continuous(labels = scales::dollar_format(prefix = "$")) +
ylab("Neighborhood median rent price") + xlab(NULL) +
plotTheme() +
theme(
legend.position = "none",
panel.spacing.y = unit(1, "lines")
) +
scale_fill_manual(values=palette_8_colors) +
labs(title="Time series for highest growth neighborhoods, Boston",
subtitle="Nominal prices (2013-2019); Median; Ribbon indicates 1 standard deviation",
caption="Source:")
time.series