First we need to install the required packages|
install.packages(“leaflet”)
install.packages(“leaflet”) install.packages(“sp”) # Now we need to load
the packages to work in this R session library(leaflet) library(sp)
biketheft = read.csv(“biketheft.csv”) > class(biketheft
\(Latitude)
[1] "numeric"
> class(biketheft\)Type) [1] “character” biketheft
\(Longitude <-
as.numeric(biketheft\)Longitude) biketheft
\(Latitude <-
as.numeric(biketheft\)Latitude) biketheft.SP <-
SpatialPointsDataFrame(biketheft[,c(6,7)], biketheft[,-c(6,7)]) bikeicon
<- makeIcon(iconUrl = “bikeicon.png”, iconWidth = 34, iconHeight =
50, iconAnchorX = 17, iconAnchorY = 48) m <- leaflet() %>%
addTiles() m m <- leaflet() %>% addTiles() %>% addMarkers(data
= biketheft, lng = ~Longitude, lat = ~Latitude, icon = bikeicon,
clusterOptions = markerClusterOptions(showCoverageOnHover = FALSE),
popup = ~paste(“
Neighborhood:”,biketheft
\(Neighbourhood,
"<br
/><b>Address:</b>",biketheft\)Hundred_Block,
“
Date (Y/M/D):”,biketheft
\(Date,
"<br
/><b>Time (Hr:Min):</b>",biketheft\)Time)) m
m <- leaflet() %>% addTiles() %>% addMarkers(data = biketheft,
lng = ~Longitude, lat = ~Latitude, icon = bikeicon, clusterOptions =
markerClusterOptions(showCoverageOnHover = FALSE), popup =
~paste(“
Neighborhood:”,biketheft
\(Neighbourhood,
"<br
/><b>Address:</b>",biketheft\)Hundred_Block,
“
Date (Y/M/D):”,biketheft
\(Date,
"<br
/><b>Time (Hr:Min):</b>",biketheft\)Time))
%>% addControl(position = “bottomright”, print(“
Author: Your Name
Data Source:
VPD Data Portal
(2022)
<br />GEOS 372 | Lab Section: X</p>"))
m m <- leaflet() %>% addTiles() %>% addMarkers(data =
biketheft, lng = ~Longitude, lat = ~Latitude, icon = bikeicon,
clusterOptions = markerClusterOptions(showCoverageOnHover = FALSE),
popup = ~paste(“
Neighborhood:”,biketheft
\(Neighbourhood,
"<br
/><b>Address:</b>",biketheft\)Hundred_Block,
“
Date (Y/M/D):”,biketheft
\(Date,
"<br
/><b>Time (Hr:Min):</b>",biketheft\)Time))
%>% addControl(position = “bottomright”, print(“
Author: Your Name
Data Source:
VPD Data Portal (2022)
GEOS 372 | Lab Section: X
“)) %>% addLegend(position =”bottomright”, colors =
c(“#91d467”,“#ebc83d”,“#f68f42”), labels = c(“< 10”, “< 100”,
“100+”), opacity = 1, title = “Number of Bike Thefts”) m