library(tidyverse)
library(skimr)
library(ggthemes)
library(ggmap)
library(sf)
Classwork 9
geom_sf()
and ggmap()
Loading R packages
Question 1. NYC dog bites with geom_sf()
The following dataset is for Question 1:
# GeoPackage file (.gkpg), a modern format for map data
<- st_read("https://bcdanl.github.io/data/nyc_zips_sf.gkpg") # sf format nyc_zips_sf
Reading layer `nyc_zips_sf' from data source
`https://bcdanl.github.io/data/nyc_zips_sf.gkpg' using driver `GPKG'
Simple feature collection with 262 features and 11 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: -74.25576 ymin: 40.49584 xmax: -73.6996 ymax: 40.91517
Geodetic CRS: WGS 84
<- read_csv("https://bcdanl.github.io/data/nyc_dog_bites_all.csv") nyc_dog_bites
<- read_csv(
nyc_dog_license 'https://bcdanl.github.io/data/nyc_dog_license.csv')
- Plot a ZIP code level map of dog bite rate. \[ \text{Dog Bite Rate} = \frac{\text{Number of dog bites}}{\text{Number of dogs}} \]
Question 2. Google Map Routes
- Plot a Google Map of Manhattan showing the following three routes:
<- route(
route1 from = "Central Park, NYC",
to = "Empire State Building, NYC",
mode = "driving",
structure = "route"
)
<- route(
route2 from = "Empire State Building, NYC",
to = "Times Square, NYC",
mode = "driving",
structure = "route"
)
<- route(
route3 from = "Times Square, NYC",
to = "Central Park, NYC",
mode = "driving",
structure = "route"
)
- In your map:
- Include a legend identifying each route;
- Mark both origins and destinations with distinct points;
- Add labels to clearly indicate each origin and destination.
Question 3. đźš• NYC Yellow Taxi Trip Analysis to the MET
You are provided a sample dataset of NYC yellow taxi trips from March 2016:
<- read_csv("https://bcdanl.github.io/data/yellow_tripdata_2016-03-sample.csv") nyc_taxi
Q3a
Create a data.frame whose taxi trip drop off is at the Metropolitan Museum of Art (MET), and taxi trip pick up is within Manhattan.
- Coordinates for the MET drop-off are defined by the
range_lon_MET
andrange_lat_MET
vectors:
<- c(-73.963, -73.9615)
range_lon_MET <- c(40.7785, 40.780) range_lat_MET
- Coordinates for the Manhattan pick-up are defined by the
range_lon
andrange_lat
vectors:
<- c(-74.03, -73.92)
range_lon_Manhattan <- c(40.70, 40.88) range_lat_Manhattan
Q3b
From the resulting data.frame in Q3a, retrieve the Google Maps’ routes for the top 2 most expensive taxi trips to the MET.
Q3c
- Plot a Google Map of Manhattan showing the top 2 most expensive tax trip path to the MET.
- Visualize pick-up locations using a marker.
- Display the label of “Metropolitan Museum of Art” on the map.
Discussion
Welcome to our Classwork 9 Discussion Board! đź‘‹
This space is designed for you to engage with your classmates about the material covered in Classwork 9.
Whether you are looking to delve deeper into the content, share insights, or have questions about the content, this is the perfect place for you.
If you have any specific questions for Byeong-Hak (@bcdanl) regarding the Classwork 9 materials or need clarification on any points, don’t hesitate to ask here.
All comments will be stored here.
Let’s collaborate and learn from each other!