You will need plotly
installed to run the code. If you do not have it installed, run install.packages("plotly")
.
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 plotly for plotting
library(plotly)
## Warning: package 'plotly' was built under R version 3.5.1
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.1
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
# Settings for the plot -- complete, but some other options are listed in the comments
geo <- list(
showland = TRUE,
showlakes = TRUE,
showcountries = TRUE,
showocean = TRUE,
countrywidth = 0.5,
landcolor = toRGB("grey90"), # Run colors() after loading plotly to see available colors
lakecolor = toRGB("aliceblue"),
oceancolor = toRGB("aliceblue"),
projection = list(
type = 'orthographic', # Consider trying 'equirectangular' or 'steriographic'
rotation = list(
lon = 100, # This sets the center longitude
lat = 1, # This sets the center latitude
roll = 0
)
),
lonaxis = list(
showgrid = TRUE,
gridcolor = toRGB("gray40"),
gridwidth = 0.5
),
lataxis = list(
showgrid = TRUE,
gridcolor = toRGB("gray40"),
gridwidth = 0.5
)
)
# Plot
plot_geo() %>%
add_markers(data=mg,
x = ~lon,
y = ~lat,
text=~paste("Time: ", dt)) %>%
layout(showlegend = TRUE, geo = geo,
title = 'Typhoon Mangkhut, through 2018 Sept 17')
## Warning: package 'bindrcpp' was built under R version 3.5.1