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 Intensity
## 1 59 59 2018SEP07 060000 12.10 166.20 2.2
## 2 60 60 2018SEP07 063000 12.03 166.16 2.3
## 3 61 61 2018SEP07 070000 11.98 166.11 2.3
## 4 62 62 2018SEP07 073000 11.95 166.04 2.4
## 5 63 63 2018SEP07 080000 11.94 165.96 2.4
# Load plotly for plotting
library(plotly)
## Loading required package: ggplot2
##
## 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, full path')