Passing 2 addresses to the Nominatim single address geocoder
Query completed in: 2 seconds
addresses
# A tibble: 2 × 4
address lat long name
<chr> <dbl> <dbl> <chr>
1 50 Payson Ave, Easthampton, MA 42.3 -72.7 City Hall
2 Holyoke Community College, Holyoke,MA 42.2 -72.7 HCC
Let’s plot those with ggplot.
ggplot(addresses) +geom_point(aes(long,lat))
#coord_quickmap()
Not very exciting. We’ll add it it in a moment.
Let’s build a map of Massachusetts with the map_data() function
ma_counties <-map_data("county", "massachusetts") %>%select( long, lat, group, id = subregion)head(ma_counties)
long lat group id
1 -70.67435 41.73997 1 barnstable
2 -70.53683 41.79727 1 barnstable
3 -70.53683 41.79727 1 barnstable
4 -70.51392 41.78008 1 barnstable
5 -70.47954 41.75716 1 barnstable
6 -70.41078 41.73425 1 barnstable
Notice there are a lot of points for barnstable. Those are the vertices of a polygon. Let’s draw the polygon with the points.
name long lat
1 Andover MA -71.14 42.65
2 Arlington MA -71.16 42.42
3 Attleboro MA -71.30 41.93
4 Barnstable Town MA -70.30 41.70
5 Beverly MA -70.84 42.56
6 Billerica MA -71.26 42.56