knitr::opts_chunk$set(echo = TRUE)
Loading the libraries
## Loading required package: leaflet
## Warning: package 'leaflet' was built under R version 3.3.2
The Key objective of this assigniment is to use the leaflet library to display some information on a properly formated RMD file. The assigniment also ask us to be creative…
So, just to make things a bit more interesting, I decided to map my favorite Burgers, Bacon and Beers places (The triple B ) in my city which happens to be Sorocaba, a city near São Paulo here in Brazil.
It’s important to state clearly that this papper do not have any comercial aspect. I just Like Bacon, Burguers and Beers.
To get the latitude and longitude data, I used Google Maps to source the data. I also add my own star based rating to each place. I also used Google Images to source the icons used as markers.
I also decide to take the dataframe approach instead of manipulate each individual list, just to make things a bit more what I think is a real case.
lat <- c(-23.495330, -23.539787,-23.519325, -23.512261, -23.503998, -23.507167, -23.461070)
lng <- c(-47.435167,-47.467391,-47.470055,-47.493269,-47.470684,-47.470591, -47.422972)
joint <- c("Bardolino", "Cervejario", "Mestre Cervejeiro", "Alabama Burguer","A Cervejaria","Lucky Wings", "Burgman ")
rate <- c(5,4,3,4.3,3.3,3.55,2.88)
typeOfPlace <- c("Bar","Store" ,"Store","Bar","Bar","Bar","Bar")
df <- data.frame(joint,lat,lng,rate,typeOfPlace)
img <- icons(ifelse(df$typeOfPlace=="Bar",
"http://www.depot4.com.br/wp-content/uploads/2015/07/Burguers-prontos.png",
"https://www.shareicon.net/data/128x128/2016/07/19/798436_drink_512x512.png"),
iconHeight = 35,
iconWidth =30)
starImgRef <- "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAVCAMAAAB1/u6nAAAAkFBMVEX////syHPqxGnpv2DnulbltkzjsULirDnuzXzgqC/x1pDw0Ybr5MfpyHXkxG24my359u3eoyXWxYTGr1Xm27TBnzDAp0Lz25r49uzy7tzWpjPHrVO0lSG8oDjQu3DOpTTNt2ff06Xv6dLbzprRq0DImR3JmR3ayY7XvmjQslPBqEfSvnfRt1zdxnnizYTo4L8g7bsSAAAAxklEQVQYlW2Q6RaCIBSEKW2xDJLNJUw0yTTL93+7qEio/P5wmHPP3DsDwEgYgikImVIHQqbGyf0m/9WQxzFP/2R5ieP++KsmaKNB+/FP8VWSjrdbTcs7Iq8N3YMKtT2Eu7VhB2HfIr0D53D2xRw1T5sy9+YOHqdve4p8b6QWw2dt1dW+oXZvPxULAyvdLMXSULiJ8mxlyHI3YhAEmRCZfmxQMLAoUpyWXEURs+1ipRjWUwlmZ9XYqoU0Z6UHYUtPKrunenk/AHDBEAn52/V6AAAAAElFTkSuQmCC"
leaflet(df) %>%
setView(lat = -23.505534, lng=-47.445829,zoom=14) %>%
addTiles() %>%
addMarkers(lng = ~lng, lat = ~lat,
popup = ~paste0("<b>", df$joint,"</b><br>",as.character(df$rate) ," <b>X</b> <img src=", starImgRef, ">" ),
popupOptions = popupOptions(closeButton = FALSE,zoomAnimation = TRUE),
label= ~as.character(joint),
icon = img)