You will need leaflet
installed to run the code. If you do not have it installed, run install.packages("leaflet")
The fourth map also requires leaflet.extras
installed. If you do not have it installed, run install.packages("leaflet.extras")
Use knit to run this code.
# The file mg.csv contains the following information for Typhoon Mangkhut:
# - lat: latitude
# - lon: longitude (fixed)
# - dt: Date time in format "%Y%b%d %H%M%S"
mg <- read.csv("mg.csv")
# Sample of the data:
mg[1:5,]
## X.1 X dt lat lon
## 1 59 59 2018SEP07 060000 12.10 166.20
## 2 60 60 2018SEP07 063000 12.03 166.16
## 3 61 61 2018SEP07 070000 11.98 166.11
## 4 62 62 2018SEP07 073000 11.95 166.04
## 5 63 63 2018SEP07 080000 11.94 165.96
# Load leaflet for plotting
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.5.1
# Plot out the data -- basic graph
leaflet() %>%
addTiles() %>%
setView(lng = 136, lat = 20, zoom=3) %>%
addMarkers(data=mg, lng=~lon, lat=~lat, label = ~dt)
# Plot out the data -- clustered graph
leaflet() %>%
addTiles() %>%
setView(lng = 136, lat = 20, zoom=3) %>%
addMarkers(data=mg, lng=~lon, lat=~lat, label = ~dt,
clusterOptions = markerClusterOptions())
# Plot out the data using circles
leaflet() %>%
addTiles() %>%
setView(lng = 136, lat = 20, zoom=3) %>%
addCircleMarkers(data=mg, lng=~lon, lat=~lat, label = ~dt,
stroke = TRUE, radius=2, color="red")
# Blinking plot
library(leaflet.extras)
## Warning: package 'leaflet.extras' was built under R version 3.5.1
ty_icons <- pulseIcons(color='red', # supports hex colors like "#C0C0C0"
heartbeat = 1.6, #heartbeat is frequency of pulsing
iconSize=3)
leaflet() %>%
addTiles() %>%
setView(lng = 136, lat = 20, zoom=3) %>%
addPulseMarkers(data=mg, lng=~lon, lat=~lat, label = ~dt, icon=ty_icons)