-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSHSAT leaflet map.Rmd
137 lines (100 loc) · 3.79 KB
/
SHSAT leaflet map.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
title: "Leaflet Maps"
author: "Andrea Tillotson"
date: "5/23/2022"
output: html_document
---
```{r, echo = FALSE, warning = FALSE, message = FALSE}
library(tidyverse)
```
```{r, echo = FALSE, warning = FALSE, message = FALSE}
points <- read.csv("point_data.csv")
points_add <- read.csv("point_data_as_csv.csv") %>%
unite("Full_Address", 10:12, sep = ", ", remove = FALSE) %>%
select(DBN, Full_Address)
test <- read.csv("full_missing.csv") %>%
unite("Full_Address", c(17, 19:20), sep = ", ", remove = FALSE) %>%
select(DBN, Full_Address)
full_add <- rbind(points_add, test)
points <- points %>% left_join(full_add)
```
```{r, echo = FALSE, warning = FALSE, message = FALSE}
library(ggmap)
#points_geo <- points %>%
# mutate_geocode(Full_Address)
#points_geo <- points_geo %>%
# mutate(latitute = lat,
# longitude = lon)
#writexl::write_xlsx(points_geo, "points_geo.xlsx")
points_geo <- readxl::read_xlsx("points_geo.xlsx")
```
```{r}
#adding school district boundaries
library(rgdal)
school_districts = readOGR(dsn="./shapefiles/polygon data/3_13/.", verbose=FALSE)
```
```{r}
school_districts <- spTransform(school_districts, CRS("+proj=longlat +ellps=GRS80"))
```
```{r}
leaflet() %>% addTiles() %>%
addPolygons(data=school_districts, weight=1, col='#333333', smoothFactor = 0.5, fillColor = ~colorQuantile("YlOrRd", tester_count_high)(tester_count_high), fillOpacity = 0.3)
```
```{r, echo = FALSE, warning = FALSE, message = FALSE}
library(leaflet)
points_geo <- points_geo %>% mutate(offers = case_when(
fof_offers == 1 ~ "Five or fewer",
fof_offers == 0 ~ "More than five"
))
pal <- colorFactor("Set1", domain = points_geo$offers)
color_offers <- pal(points_geo$offers)
content <- paste("<font size ='+1'><b>Middle School:</b><br/>", points_geo$MS, "<br/</font size><br/>",
"<b>Borough:</b>", points_geo$Borough,"<br/>",
"<b>Students in testing pool:</b>", points_geo$total_students,"<br/>",
"<b># of students tested:</b>", points_geo$testers_count,"<br/>",
"<b># of students offered spots:</b>", points_geo$total_offers, "<br/>",
"<b>Gifted and talented?</b>", points_geo$G_T, "<br/>",
"<b>High school program?</b>", points_geo$HS_Program, "<br/>",
"<b>Serves citywide?</b>", points_geo$Citywide, "<br/>")
library(htmltools)
tag.map.title1 <- tags$style(HTML("
.leaflet-control.map-title {
transform: translate(-50%,20%);
position: fixed !important;
left: 50%;
text-align: center;
padding-left: 10px;
padding-right: 10px;
background: rgba(0,128,128,0.3);
font-weight: bold;
font-size: 15px;
}
"))
title1 <- tags$div(
tag.map.title1, HTML("NYC middle schools and SHSAT offers to Specialised High schools")
)
```
```{r}
#polygon data
#left_join by CSD
combine <- school_districts@data %>%
left_join(polygon_data, by = c(CSD = "CSD"))
school_districts@data <- combine
```
```{r}
head(school_districts@data)
polygon_data <- read_csv("polygon_data.csv")
head(polygon_data)
```
```{r, echo = FALSE, warning = FALSE, message = FALSE}
leaflet(points_geo) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addCircles(color = color_offers, popup = content,
lat = ~lat, lng = ~lon) %>%
addLegend(position = "bottomleft", opacity = 1,
pal = pal, values = ~points_geo$offers, title="Offers") %>%
addControl(title1, position="topleft", className="map-title") %>%
addPolygons(data=school_districts, weight=1, col='#333333', smoothFactor = 0.5, fillColor = ~colorQuantile("YlGnBu", tester_count_high)(tester_count_high), fillOpacity = 0.3,
label = ~stringr::str_c(CSD, ' ', formatC(tester_count_high, big.mark = ',', format='d')),
labelOptions = labelOptions(direction='auto'))
```