options(DT.options = list(fixedHeader = TRUE, paging = TRUE, scrollX = TRUE))
Filtering & Augmenting Datset
Check out ds
glimpse(j)
## Rows: 15
## Columns: 12
## $ city <chr> "Tokyo", "Yokohama", "Osaka", "Nagoya", "Sapporo"...
## $ lat <dbl> 35.68500, 35.43333, 34.68333, 35.18333, 43.06667,...
## $ lng <dbl> 139.7514, 139.6500, 135.5167, 136.9000, 141.3500,...
## $ country <chr> "Japan", "Japan", "Japan", "Japan", "Japan", "Jap...
## $ iso2 <chr> "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "...
## $ admin <chr> "Tokyo", "Kanagawa", "Osaka", "Aichi", "Hokkaido"...
## $ capital <chr> "primary", "admin", "admin", "admin", "admin", "a...
## $ population <dbl> 35676000, 3697894, 11294000, 3230000, 2544000, 15...
## $ population_proper <dbl> 8336599, 3697894, 2592413, 2191279, 1861786, 1528...
## $ label <chr> "city: Tokyo<br>prefecture: Tokyo<br>population: ...
## $ pop_rank <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
## $ itinerary.day <dbl> 3, 3, 5, 4, 1, 5, 4, 7, 3, 6, 2, 5, 7, 4, 6
j %>% DT::datatable()
Choose Specified ‘Esri’ Base Maps
library(data.table)
Esri.maps = providers %>% names %>% as_tibble() %>% filter(value %like% 'Esri') %>% pull
#choose the best ones
(Esri.maps = Esri.maps[c(1,3,4,10,11)])
## [1] "Esri" "Esri.DeLorme" "Esri.WorldTopoMap"
## [4] "Esri.NatGeoWorldMap" "Esri.WorldGrayCanvas"
Create factor color palette
#---------------------------------------------------
# FACTOR Color Palette
#---------------------------------------------------
#adding color palette using colorFactor
pal.itinerary.day = colorFactor(
palette = RColorBrewer::brewer.pal(
n = j$itinerary.day %>% unique() %>% length, #count of unique counties
name = 'Set3'),
levels = j$itinerary.day %>% unique() #names of unique county
)
Create Final Map
j %>% leaflet(options = leafletOptions(minZoom = 5, dragging = TRUE )) %>% #1 zoom option
#----------------------------
addProviderTiles(Esri.maps[1], group = Esri.maps[1]) %>%
addProviderTiles(Esri.maps[2], group = Esri.maps[2]) %>%
addProviderTiles(Esri.maps[3], group = Esri.maps[3]) %>%
addProviderTiles(Esri.maps[4], group = Esri.maps[4]) %>%
addProviderTiles(Esri.maps[5], group = Esri.maps[5]) %>%
#----------------------------
addCircleMarkers(
label = ~map(label, htmltools::HTML), # add custom labels
color = ~pal.itinerary.day(itinerary.day), #add custom color palette
fillOpacity = 0.7, opacity = 0.9
) %>%
addLayersControl(
baseGroups = Esri.maps
) %>%
#----------------------------
addResetMapButton() %>% #2 reset default view
addSearchOSM(options = searchFeaturesOptions(zoom = 7)) %>% #3 search visible map
#----------------------------
leaflet::addLegend(
title = 'Itinerary Day #',
position = 'topright',
pal = pal.itinerary.day,
values = j$itinerary.day %>% unique()
)
Reflections
- Add more interesting data
- famous foods/sights in each city
- Add other functionality
- toggle each itinerary.day group
- Add html links within the label to bring you to blogs, YT videos, etc.,