1.Introduction

Create a web page using R Markdown that features a map created with Leaflet.

Host your webpage on either GitHub Pages, RPubs, or NeoCities.

Your webpage must contain the date that you created the document, and it must contain a map created with Leaflet. We would love to see you show off your creativity!

Review criteria

The rubric contains the following two questions:

  1. Does the web page feature a date and is this date less than two months before the date that you’re grading this assignment?
  2. Does the web page feature an interactive map that appears to have been created with Leaflet? ### Example Submissions Here’s an extremely minimal passing example, but we hope your submission is much cooler!

2.Installation

# Check the leaflet package.
necessary <- c("leaflet", "ggmap")
installed <- necessary %in% installed.packages()[, "Package"]

if (length(necessary[!installed]) >=1) {
  install.packages(necessary[!installed])
}

3. First try

# Load the package
library(leaflet)
# Set my first map
myMap <- leaflet() %>%
  addTiles()
# Show the map
myMap

4. Adding marker

I want to make a map of where I have been to, so I use the ggmap package for getting longitude/latitude of every city.

# Load the ggmap package
library(ggmap)
# Get a data from city name.
myLocation <- geocode("tokyo", output = "more")
# Add marker
myMap <- myMap %>%
  addMarkers(lat = myLocation$lat, 
             lng = myLocation$lon, 
           popup = myLocation$address)
myMap

5. Adding many markers

countries <- c("china","australia","japan")
myLocations <- geocode(countries, output = "more")
myLocations %>% 
  leaflet() %>%
  addTiles() %>%
  addMarkers(popup = myLocations$address)

6. Mapping Clusters

Hide the details of cities.

myCities <- geocode(cities, output = "more")
myCities %>% 
  leaflet() %>%
  addTiles() %>%
  addMarkers(clusterOptions = markerClusterOptions())