-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate1b.Rmd
244 lines (194 loc) · 8.07 KB
/
template1b.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
---
title: "DC Lead Pipe Replacement"
output:
flexdashboard::flex_dashboard:
theme: bootstrap
logo: "etc/logo.svg"
favicon: "etc/icon.png"
navbar:
- { title: "Map", href: "#map", align: left }
- { title: "Replacement", href: "#replacement", align: left }
- { title: "About", href: "#about", align: left}
- { title: "Data Download", icon: "fa-download", href: "https://www.dcwater.com/sites/default/files/cleanrivers/service-line.csv", align: left }
- { title: "Source Code", icon: "fa-github", href: "https://github.com/WaterDataLab/lead", align: left, target: "_blank"}
orientation: rows
vertical_layout: fill
css: "etc/style.css"
---
<script>
$('.navbar-logo').wrap('<a href="https://www.watergrid.io" target="_blank">');
</script>
```{r setup, include=FALSE}
library(flexdashboard)
library(leaflet)
library(tidyverse)
library(sf)
library(leafgl)
# colors
pal <- rcartocolor::carto_pal(12, "Bold")
# DC lead data
url <- "https://www.dcwater.com/sites/default/files/cleanrivers/service-line.csv"
# webgl
df <- read_csv(url) %>%
janitor::clean_names()
# clean up
df <- df %>%
select(premise_address, public_service_material,
private_service_material, longitude, latitude) %>%
st_as_sf(coords = c("longitude", "latitude"), crs = 4326)
# color points based on lead
lead <- c("Lead_brass", "Iron with lead", "Lead and copper",
"Lead", "LEAD AND COPPER", "LEAD\n",
"Galvanized iron with lead")
# colorblind-safe palette for points
pal_pts <- rcartocolor::carto_pal(name = "Safe")
col_privatelead = pal_pts[2] # pink
col_publiclead = pal_pts[3] # yellow
# add colors depending on if lead is present
df <- df %>%
mutate(
public_lead = ifelse(public_service_material %in% lead,
"grey50", "green"),
public_lead = ifelse(public_service_material == "No information",
"white", public_lead),
private_lead = ifelse(private_service_material %in% lead,
"grey50", "green"),
private_lead = ifelse(private_service_material == "No information",
"white", private_lead),
popup = paste0(
"<b>", premise_address, "</b><br>",
"<b>Public: </b>", public_service_material, "<br>",
"<b>Private: </b>", private_service_material)
)
```
Map {.hidden}
=====================================
```{r}
# make leaflet
leaflet() %>%
# 4 basemaps
addProviderTiles(provider = providers$CartoDB.Positron, group = "Light") %>%
addProviderTiles(provider = providers$CartoDB.DarkMatter, group = "Dark") %>%
addProviderTiles(provider = providers$OpenStreetMap, group = "Street") %>%
addProviderTiles(provider = providers$Esri.WorldImagery, group = "World") %>%
# public lead points
addGlPoints(
data = filter(df, public_lead == "grey50"),
fillColor = "public_lead",
fillOpacity = 1,
radius = 20,
group = "Lead"
) %>%
# public no lead points
addGlPoints(
data = filter(df, public_lead != "grey50"),
fillColor = "public_lead",
fillOpacity = 1,
radius = 20,
group = "No lead"
) %>%
# private lead points
addGlPoints(
data = filter(df, private_lead == "grey50"),
fillColor = "private_lead",
fillOpacity = 1,
radius = 10,
popup = "popup",
group = "Lead"
) %>%
# private no lead points
addGlPoints(
data = filter(df, private_lead != "grey50"),
fillColor = "private_lead",
fillOpacity = 1,
radius = 10,
popup = "popup",
group = "No lead"
) %>%
flyTo(lng = mean(st_coordinates(df)[, 1]),
lat = mean(st_coordinates(df)[, 2]), zoom = 12) %>%
leaflet.extras::suspendScroll() %>%
leaflegend::addLegendImage(
images = "legend.png",
labels = "",
title = htmltools::tags$div(
"Legend",
style = "font-size: 16px; text-align: center; margin-bottom: 5px;"),
position = "topright",
orientation = "vertical",
height = 165, width = 180) %>%
addLayersControl(
overlayGroups = c("Lead", "Lead", "No lead"),
baseGroups = c("Light", "Dark", "Street", "World"),
options = layersControlOptions(collapsed = FALSE),
position = "topright"
)
```
Replacement {.hidden}
=====================================
<center>
**VALUES MADE UP FOR DEMONSTRATION PURPOSES**
</center>
<br>
Row
-------------------------------------
### **Public** replacement rate (since 2019) {.value-box}
```{r}
# value boxes
# icons: https://ionic.io/ionicons/v2
valueBox("51%",
icon = "ion-merge", color = col_publiclead,
caption = "Public replacement rate (since 2019)")
```
### **Public** pipes replaced (since 2019) {.value-box}
```{r}
valueBox("1,265 pipes",
icon = "ion-merge", color = col_publiclead,
caption = "Public replacement count (since 2019)")
```
### **Private** replacement rate (since 2019) {.value-box}
```{r}
valueBox("89%",
icon = "ion-ios-home", color = col_privatelead,
caption = "Private replacement rate (since 2019)")
```
### **Private** pipes replaced (since 2019) {.value-box}
```{r}
valueBox("912 pipes",
icon = "ion-ios-home", color = col_privatelead,
caption = "Private replacement count (since 2019)")
```
Row
-------------------------------------
### **Lead pipes remaining**, last updated `r paste(Sys.time())`
```{r}
rates <- data.frame(
time = rep(c(2019, 2020, 2021), 2),
count = c(2643, 1578, 1289, 874, 546, 95),
type = c(rep("Public", 3), rep("Private", 3))
) %>%
mutate(type = factor(type, levels = c("Public", "Private")))
p <- ggplot(rates, aes(time, count, color = type)) +
geom_line() +
geom_point() +
scale_color_manual(values = c(col_privatelead, col_publiclead),
breaks = c("Private", "Public")) +
scale_x_continuous(breaks = 2019:2021) +
labs(x = "", y = "Lead Pipes Remaining", color = "Type")
plotly::ggplotly(p)
```
About {.hidden}
=====================================
### **Why replace lead pipes?**
<iframe width="100%" height="285" src="https://www.youtube.com/embed/6DJDGtM_d5Y" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" data-external="1"></iframe>
#### **History**
DC Water has historic data for the public portion of the water service line from plumbing records, service installation, and some maintenance activity that was reported to DC Water or another utility agency. Where DC Water has verified the pipe material by test pit or visual observation during a public space and/or private property service line replacement, the data source will be shown as "excavation" and is accurate as of the given inspection date. All other information is based upon historic records, but has not been confirmed. The map reflects the information DC Water has available for each active customer in the District.
### **Disclaimer**
The maps provided by the District of Columbia Water and Sewer Authority (“D.C. Water”) are based on historical data, information directly provided by customers, and in some cases, information acquired during physical inspections. DC Water does not guarantee the accuracy of these records and maps, which shall be used for the sole purpose of providing property owners and residents with DC Water’s best available data regarding their private water services, and not for any commercial, legal or other use. These records will be updated constantly as D.C. Water gathers additional information. D.C. Water requests that customers provide to it records of any service line replacements performed by property owners. D.C. Water reserves the right to alter, amend or terminate at any time the display of these maps and records.
#### **More information**
- <a href="https://www.dcwater.com/faq-page/74" target="_blank">Service Lines - Fact Sheet</a>
- <a href="https://www.dcwater.com/Lead" target="_blank">DC Water Lead information</a>
### **Contact**
* _General inquiries_: 202-787-2000
* _Email_: [email protected]
* _Twitter_: <a href="https://twitter.com/dcwater" target="_blank">@ dcwater</a>