-
Notifications
You must be signed in to change notification settings - Fork 0
/
9-28_walk_request.R
261 lines (225 loc) · 10.4 KB
/
9-28_walk_request.R
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#Filters
source("./02_Scripts/000_Init.R")
library(tidygeocoder)
library(dplyr)
#####################
##### Trestle Glen Road. All adresses Up to Vallent (where it gets too steep to walk) ##########
#####################
EBRPD_district_2_voter_data <- readRDS("EBRPD_district_2_voter_data.rds")
EBRPD_district_2_voter_data_2 <- EBRPD_district_2_voter_data %>%
rename(party_category = Party_Category) %>%
mutate(voted_in_2016_general = case_when(x52_11_08_2016_2016_general_election_127_eligibility == "V" ~ "Yes",
x52_11_08_2016_2016_general_election_127_eligibility == "A" ~ "Yes",
x52_11_08_2016_2016_general_election_127_eligibility == "N" ~ "No",
TRUE ~ "not eligable")) %>%
filter(str_detect(mail_street, "TRESTLE GLEN"), #saranapp (walnut Creek) (Lafayette) - Oakland Piedmont Onthclair
party_category == "Democratic",
voted_in_2020_general == "Yes"
)
# Assuming your data frame is named 'df' with columns: 'Street', 'City', 'State', 'Zip'
# Create a full address column
df <- EBRPD_district_2_voter_data_2 %>%
mutate(mail_zip = substr(mail_zip, 1, 5))%>%
#select(-full_address) %>%
#only for mapping
mutate(mail_street = gsub("\\s+\\d+$", "", mail_street)) %>%
mutate(full_address = paste( mail_street, mail_state, mail_zip, sep = ", ")) %>%
filter(!str_detect(mail_street, "PO BOX"),
mail_state == "CA" ,
house_number < 1700) %>%
distinct(full_address, .keep_all = TRUE) %>%
arrange(mail_street, mail_zip) %>%
select(full_address,apartment_number, house_number, party, name_first,name_last, email, phone_1, voted_vs_opportunities_group, voted_in_2020_general ,precinct_name) %>%
arrange(house_number, full_address, apartment_number)
geocoded_data <- df %>%
geocode(address = full_address, method = 'osm', lat = latitude, long = longitude)
write.csv(df, "TRESTLE GLEN_clean_distinct.csv")
write.csv(EBRPD_district_2_voter_data_2, "TRESTLE GLEN_all_info.csv")
######### MAP ------------------------
dot_map <- leaflet(data = geocoded_data) %>%
addTiles() %>%
addCircleMarkers(
lng = ~longitude,
lat = ~latitude,
radius = 2,
color = "blue",
fillOpacity = 0.6,
label = ~full_address, # Add label to show full address on hover
labelOptions = labelOptions(
noHide = FALSE,
direction = "auto"
)
)
dot_map
# Save the map to an HTML file
library(htmlwidgets)
saveWidget(dot_map, file = "dot_TRESTLE_GLEN_Hover.html")
########################
########################
#####################
##### Shafter off college all. All the way to MacArthur(Manila/Lawton and Chabot too) ##########
#####################
EBRPD_district_2_voter_data <- readRDS("EBRPD_district_2_voter_data.rds")
EBRPD_district_2_voter_data_2 <- EBRPD_district_2_voter_data %>%
rename(party_category = Party_Category) %>%
mutate(voted_in_2016_general = case_when(x52_11_08_2016_2016_general_election_127_eligibility == "V" ~ "Yes",
x52_11_08_2016_2016_general_election_127_eligibility == "A" ~ "Yes",
x52_11_08_2016_2016_general_election_127_eligibility == "N" ~ "No",
TRUE ~ "not eligable")) %>%
filter(str_detect(mail_street, "Shafter|SHAFTER|Chabot|CHABOT|LAWTON|Lawton|Manila|MANILA"), #saranapp (walnut Creek) (Lafayette) - Oakland Piedmont Onthclair
party_category == "Democratic",
voted_in_2020_general == "Yes"
)
# Assuming your data frame is named 'df' with columns: 'Street', 'City', 'State', 'Zip'
# Create a full address column
df <- EBRPD_district_2_voter_data_2 %>%
mutate(mail_zip = substr(mail_zip, 1, 5),
street_name = str_remove_all(mail_street, "[0-9]"))%>%
#select(-full_address) %>%
#only for mapping
mutate(mail_street = gsub("\\s+\\d+$", "", mail_street)) %>%
mutate(full_address = paste( mail_street, mail_state, mail_zip, sep = ", ")) %>%
filter(!str_detect(mail_street, "PO BOX"),
mail_state == "CA" ) %>%
distinct(full_address, .keep_all = TRUE)%>%
arrange(street_name, house_number, apartment_number) %>%
# arrange(mail_street, mail_zip) %>%
select(full_address,apartment_number, house_number, party, name_first,name_last, email, phone_1, voted_vs_opportunities_group, voted_in_2020_general ,precinct_name)
geocoded_data <- df %>%
geocode(address = full_address, method = 'osm', lat = latitude, long = longitude)
saveRDS(geocoded_data ,"Shafter_clean.rds")
write.csv(df, "Shafter_clean_distinct.csv")
write.csv(EBRPD_district_2_voter_data_2, "Shafter_all_info.csv")
######### MAP ------------------------
dot_map <- leaflet(data = geocoded_data) %>%
addTiles() %>%
addCircleMarkers(
lng = ~longitude,
lat = ~latitude,
radius = 2,
color = "blue",
fillOpacity = 0.6,
label = ~full_address, # Add label to show full address on hover
labelOptions = labelOptions(
noHide = FALSE,
direction = "auto"
)
)
dot_map
# Save the map to an HTML file
library(htmlwidgets)
saveWidget(dot_map, file = "dot_Shafter_Hover.html")
################
#####################
##### 3. highland Ave between Oakland ave and Moraga ave ##########
#####################
EBRPD_district_2_voter_data <- readRDS("EBRPD_district_2_voter_data.rds")
EBRPD_district_2_voter_data_2 <- EBRPD_district_2_voter_data %>%
rename(party_category = Party_Category) %>%
mutate(voted_in_2016_general = case_when(x52_11_08_2016_2016_general_election_127_eligibility == "V" ~ "Yes",
x52_11_08_2016_2016_general_election_127_eligibility == "A" ~ "Yes",
x52_11_08_2016_2016_general_election_127_eligibility == "N" ~ "No",
TRUE ~ "not eligable")) %>%
filter(str_detect(mail_street, "highland|HIGHLAND"), #saranapp (walnut Creek) (Lafayette) - Oakland Piedmont Onthclair
party_category == "Democratic",
voted_in_2020_general == "Yes"
)
# Assuming your data frame is named 'df' with columns: 'Street', 'City', 'State', 'Zip'
# Create a full address column
df <- EBRPD_district_2_voter_data_2 %>%
mutate(mail_zip = substr(mail_zip, 1, 5),
street_name = str_remove_all(mail_street, "[0-9]"))%>%
#select(-full_address) %>%
#only for mapping
mutate(mail_street = gsub("\\s+\\d+$", "", mail_street)) %>%
mutate(full_address = paste( mail_street, mail_state, mail_zip, sep = ", ")) %>%
filter(!str_detect(mail_street, "PO BOX"),
mail_state == "CA" ) %>%
distinct(full_address, .keep_all = TRUE)%>%
arrange(street_name, house_number, apartment_number) %>%
# arrange(mail_street, mail_zip) %>%
select(full_address,apartment_number, house_number, party, name_first,name_last, email, phone_1, voted_vs_opportunities_group, voted_in_2020_general ,precinct_name)
geocoded_data <- df %>%
geocode(address = full_address, method = 'osm', lat = latitude, long = longitude)
saveRDS(geocoded_data ,"Highland_geo.rds")
geocoded_data <- geocoded_data %>%
filter(house_number != 301,
full_address != "10 HIGHLAND WAY, CA, 94611")
write.csv(df, "highland_clean_distinct.csv")
write.csv(EBRPD_district_2_voter_data_2, "highland_all_info.csv")
######### MAP ------------------------
dot_map <- leaflet(data = geocoded_data) %>%
addTiles() %>%
addCircleMarkers(
lng = ~longitude,
lat = ~latitude,
radius = 2,
color = "blue",
fillOpacity = 0.6,
label = ~full_address, # Add label to show full address on hover
labelOptions = labelOptions(
noHide = FALSE,
direction = "auto"
)
)
dot_map
# Save the map to an HTML file
library(htmlwidgets)
saveWidget(dot_map, file = "dot_highland_Hover.html")
################
#####################
##### 4. lakeshore road (go past the merchants near lake) then good flat houses rest of lakeshore. ##########
#####################
EBRPD_district_2_voter_data <- readRDS("EBRPD_district_2_voter_data.rds")
EBRPD_district_2_voter_data_2 <- EBRPD_district_2_voter_data %>%
rename(party_category = Party_Category) %>%
mutate(voted_in_2016_general = case_when(x52_11_08_2016_2016_general_election_127_eligibility == "V" ~ "Yes",
x52_11_08_2016_2016_general_election_127_eligibility == "A" ~ "Yes",
x52_11_08_2016_2016_general_election_127_eligibility == "N" ~ "No",
TRUE ~ "not eligable")) %>%
filter(str_detect(mail_street, "Lakeshore|LAKESHORE|Lakeside|LAKESIDE|BELLEVUE|Bellevue"), #saranapp (walnut Creek) (Lafayette) - Oakland Piedmont Onthclair
party_category == "Democratic",
voted_in_2020_general == "Yes"
)
# Assuming your data frame is named 'df' with columns: 'Street', 'City', 'State', 'Zip'
# Create a full address column
df <- EBRPD_district_2_voter_data_2 %>%
mutate(mail_zip = substr(mail_zip, 1, 5),
street_name = str_remove_all(mail_street, "[0-9]"))%>%
#select(-full_address) %>%
#only for mapping
mutate(mail_street = gsub("\\s+\\d+$", "", mail_street)) %>%
mutate(full_address = paste( mail_street, mail_state, mail_zip, sep = ", ")) %>%
filter(!str_detect(mail_street, "PO BOX"),
mail_state == "CA" ) %>%
#distinct(full_address, .keep_all = TRUE)%>%
arrange(street_name, house_number, apartment_number) %>%
# arrange(mail_street, mail_zip) %>%
select(full_address,apartment_number, house_number, party, name_first,name_last, email, phone_1, voted_vs_opportunities_group, voted_in_2020_general ,precinct_name)
geocoded_data <- df %>%
geocode(address = full_address, method = 'osm', lat = latitude, long = longitude)
saveRDS(geocoded_data ,"lake_geo.rds")
geocoded_data <- readRDS("lake_geo.rds")
geocoded_data <- geocoded_data %>%
filter(!str_detect(full_address,"374|3450|244|94611"))
write.csv(df, "lake_clean_distinct.csv")
write.csv(EBRPD_district_2_voter_data_2, "Lake_all_info.csv")
######### MAP ------------------------
dot_map <- leaflet(data = geocoded_data) %>%
addTiles() %>%
addCircleMarkers(
lng = ~longitude,
lat = ~latitude,
radius = 2,
color = "blue",
fillOpacity = 0.6,
label = ~full_address, # Add label to show full address on hover
labelOptions = labelOptions(
noHide = FALSE,
direction = "auto"
)
)
dot_map
# Save the map to an HTML file
library(htmlwidgets)
saveWidget(dot_map, file = "dot_Lake_Hover.html")