---
title: "Session 5 R practice, Exercise 3"
author: "Dr. Richard M. Crowley"
date: "ACCT 420, Fall 2018, Session 5"
output:
  html_document:
    theme: spacelab
    highlight: default
    toc: true
    toc_float:
      collapsed: false
    self_contained: true
---

## Exercise 3: Using Plotly for maps

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.

```{r}
# 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,]

# Load plotly for plotting
library(plotly)

# 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')
```