library(leaflet)
library(tidyverse)

Explanation

Hi!! Welcome to my LBB in this LBB i’m gonna use Zomato dataset and make interative map using leaflet that shows the locations of restaurant in Jakarta, Indonesia. Enjoy!!

Input Data

data <- read.csv("zomato.csv")

Data Inspection

head(data)
##   Restaurant.ID        Restaurant.Name Country.Code             City
## 1       6317637       Le Petit Souffle          162      Makati City
## 2       6304287       Izakaya Kikufuji          162      Makati City
## 3       6300002 Heat - Edsa Shangri-La          162 Mandaluyong City
## 4       6318506                   Ooma          162 Mandaluyong City
## 5       6314302            Sambo Kojin          162 Mandaluyong City
## 6      18189371           Din Tai Fung          162 Mandaluyong City
##                                                                   Address
## 1 Third Floor, Century City Mall, Kalayaan Avenue, Poblacion, Makati City
## 2     Little Tokyo, 2277 Chino Roces Avenue, Legaspi Village, Makati City
## 3                Edsa Shangri-La, 1 Garden Way, Ortigas, Mandaluyong City
## 4  Third Floor, Mega Fashion Hall, SM Megamall, Ortigas, Mandaluyong City
## 5        Third Floor, Mega Atrium, SM Megamall, Ortigas, Mandaluyong City
## 6 Ground Floor, Mega Fashion Hall, SM Megamall, Ortigas, Mandaluyong City
##                                     Locality
## 1  Century City Mall, Poblacion, Makati City
## 2 Little Tokyo, Legaspi Village, Makati City
## 3 Edsa Shangri-La, Ortigas, Mandaluyong City
## 4     SM Megamall, Ortigas, Mandaluyong City
## 5     SM Megamall, Ortigas, Mandaluyong City
## 6     SM Megamall, Ortigas, Mandaluyong City
##                                               Locality.Verbose Longitude
## 1       Century City Mall, Poblacion, Makati City, Makati City  121.0275
## 2      Little Tokyo, Legaspi Village, Makati City, Makati City  121.0141
## 3 Edsa Shangri-La, Ortigas, Mandaluyong City, Mandaluyong City  121.0568
## 4     SM Megamall, Ortigas, Mandaluyong City, Mandaluyong City  121.0565
## 5     SM Megamall, Ortigas, Mandaluyong City, Mandaluyong City  121.0575
## 6     SM Megamall, Ortigas, Mandaluyong City, Mandaluyong City  121.0563
##   Latitude                         Cuisines Average.Cost.for.two
## 1 14.56544       French, Japanese, Desserts                 1100
## 2 14.55371                         Japanese                 1200
## 3 14.58140 Seafood, Asian, Filipino, Indian                 4000
## 4 14.58532                  Japanese, Sushi                 1500
## 5 14.58445                 Japanese, Korean                 1500
## 6 14.58376                          Chinese                 1000
##           Currency Has.Table.booking Has.Online.delivery Is.delivering.now
## 1 Botswana Pula(P)               Yes                  No                No
## 2 Botswana Pula(P)               Yes                  No                No
## 3 Botswana Pula(P)               Yes                  No                No
## 4 Botswana Pula(P)                No                  No                No
## 5 Botswana Pula(P)               Yes                  No                No
## 6 Botswana Pula(P)                No                  No                No
##   Switch.to.order.menu Price.range Aggregate.rating Rating.color Rating.text
## 1                   No           3              4.8   Dark Green   Excellent
## 2                   No           3              4.5   Dark Green   Excellent
## 3                   No           4              4.4        Green   Very Good
## 4                   No           4              4.9   Dark Green   Excellent
## 5                   No           4              4.8   Dark Green   Excellent
## 6                   No           3              4.4        Green   Very Good
##   Votes
## 1   314
## 2   591
## 3   270
## 4   365
## 5   229
## 6   336
dim(data)
## [1] 9551   21
names(data)
##  [1] "Restaurant.ID"        "Restaurant.Name"      "Country.Code"        
##  [4] "City"                 "Address"              "Locality"            
##  [7] "Locality.Verbose"     "Longitude"            "Latitude"            
## [10] "Cuisines"             "Average.Cost.for.two" "Currency"            
## [13] "Has.Table.booking"    "Has.Online.delivery"  "Is.delivering.now"   
## [16] "Switch.to.order.menu" "Price.range"          "Aggregate.rating"    
## [19] "Rating.color"         "Rating.text"          "Votes"

Data Cleansing

Check for missing value

colSums(is.na(data))
##        Restaurant.ID      Restaurant.Name         Country.Code 
##                    0                    0                    0 
##                 City              Address             Locality 
##                    0                    0                    0 
##     Locality.Verbose            Longitude             Latitude 
##                    0                    0                    0 
##             Cuisines Average.Cost.for.two             Currency 
##                    0                    0                    0 
##    Has.Table.booking  Has.Online.delivery    Is.delivering.now 
##                    0                    0                    0 
## Switch.to.order.menu          Price.range     Aggregate.rating 
##                    0                    0                    0 
##         Rating.color          Rating.text                Votes 
##                    0                    0                    0

Great!! No missing value anymore

Now, dataset is ready to be processed and analyzed

Data Explanation

Brief explanation

str(data)
## 'data.frame':    9551 obs. of  21 variables:
##  $ Restaurant.ID       : int  6317637 6304287 6300002 6318506 6314302 18189371 6300781 6301290 6300010 6314987 ...
##  $ Restaurant.Name     : chr  "Le Petit Souffle" "Izakaya Kikufuji" "Heat - Edsa Shangri-La" "Ooma" ...
##  $ Country.Code        : int  162 162 162 162 162 162 162 162 162 162 ...
##  $ City                : chr  "Makati City" "Makati City" "Mandaluyong City" "Mandaluyong City" ...
##  $ Address             : chr  "Third Floor, Century City Mall, Kalayaan Avenue, Poblacion, Makati City" "Little Tokyo, 2277 Chino Roces Avenue, Legaspi Village, Makati City" "Edsa Shangri-La, 1 Garden Way, Ortigas, Mandaluyong City" "Third Floor, Mega Fashion Hall, SM Megamall, Ortigas, Mandaluyong City" ...
##  $ Locality            : chr  "Century City Mall, Poblacion, Makati City" "Little Tokyo, Legaspi Village, Makati City" "Edsa Shangri-La, Ortigas, Mandaluyong City" "SM Megamall, Ortigas, Mandaluyong City" ...
##  $ Locality.Verbose    : chr  "Century City Mall, Poblacion, Makati City, Makati City" "Little Tokyo, Legaspi Village, Makati City, Makati City" "Edsa Shangri-La, Ortigas, Mandaluyong City, Mandaluyong City" "SM Megamall, Ortigas, Mandaluyong City, Mandaluyong City" ...
##  $ Longitude           : num  121 121 121 121 121 ...
##  $ Latitude            : num  14.6 14.6 14.6 14.6 14.6 ...
##  $ Cuisines            : chr  "French, Japanese, Desserts" "Japanese" "Seafood, Asian, Filipino, Indian" "Japanese, Sushi" ...
##  $ Average.Cost.for.two: int  1100 1200 4000 1500 1500 1000 2000 2000 6000 1100 ...
##  $ Currency            : chr  "Botswana Pula(P)" "Botswana Pula(P)" "Botswana Pula(P)" "Botswana Pula(P)" ...
##  $ Has.Table.booking   : chr  "Yes" "Yes" "Yes" "No" ...
##  $ Has.Online.delivery : chr  "No" "No" "No" "No" ...
##  $ Is.delivering.now   : chr  "No" "No" "No" "No" ...
##  $ Switch.to.order.menu: chr  "No" "No" "No" "No" ...
##  $ Price.range         : int  3 3 4 4 4 3 4 4 4 3 ...
##  $ Aggregate.rating    : num  4.8 4.5 4.4 4.9 4.8 4.4 4 4.2 4.9 4.8 ...
##  $ Rating.color        : chr  "Dark Green" "Dark Green" "Green" "Dark Green" ...
##  $ Rating.text         : chr  "Excellent" "Excellent" "Very Good" "Excellent" ...
##  $ Votes               : int  314 591 270 365 229 336 520 677 621 532 ...

Data Pre-processing

Because we will only show the restaurants that located in Jakarta, so we must filter it. To get the center of of the map, we must find the median of the Latitude and Longitude of the restaurants.

resto <- data[data$City == "Jakarta",]
latitude <- median(resto$Latitude)
longitude <- median(resto$Longitude)

Data Visualization

We make interactive map using library Leaflet. The center of the map is setted at median value of the Latitude and Longitude of the restaurants that have we seek before. To add the markers we use function addMarkers. We can show the information of the restaurant and set the icon using popup and icon setting. After it, to save the map to .html we can use function saveWidget. In this case, I save this map with name “zomato-map.html”

ico <- makeIcon(
    iconUrl = "icon.png",
    iconWidth=30, iconHeight=30
)

leaflet(data = resto) %>%
  setView(lat = latitude, lng = longitude, zoom=13) %>%
  addTiles(group="OSM") %>%
  addProviderTiles(providers$CartoDB.DarkMatter, group="Dark") %>%
  addProviderTiles(providers$CartoDB.Positron, group="Light") %>%
  addMarkers(lat = ~Latitude, lng = ~Longitude, 
             icon = ico, 
             popup = paste("<b>",resto$Restaurant.Name,"</b>", 
                           "<br>","Address : ", resto$Address, 
                           "<br>", "<b>Rating : </b>", resto$Aggregate.rating, "/ 5"))