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!
The rubric contains the following two questions:
# Check the leaflet package.
necessary <- c("leaflet", "ggmap")
installed <- necessary %in% installed.packages()[, "Package"]
if (length(necessary[!installed]) >=1) {
install.packages(necessary[!installed])
}
# Load the package
library(leaflet)
# Set my first map
myMap <- leaflet() %>%
addTiles()
# Show the map
myMap
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
countries <- c("china","australia","japan")
myLocations <- geocode(countries, output = "more")
myLocations %>%
leaflet() %>%
addTiles() %>%
addMarkers(popup = myLocations$address)
Hide the details of cities.
myCities <- geocode(cities, output = "more")
myCities %>%
leaflet() %>%
addTiles() %>%
addMarkers(clusterOptions = markerClusterOptions())