R Markdown

Week 2 Assignment of the Coursera Developing Data Products Course. JH Data Science Specialization.

Objective: 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!

Let’s create the map, I will base it on my a recent Global Beer Market Report found here: https://www.technavio.com/report/beer-market-industry-analysis?pk_vid=df753d7a5444f6ae1595945152fae10f

library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.5.2
#Let's make an icon for each one of the 5 biggest.

Icons<- iconList(
        AnheuserIcon <- makeIcon(iconUrl = "https://cdn.countryflags.com/thumbs/united-states-of-america/flag-800.png", iconWidth = 31*215/230, 
                                 iconHeight = 31, iconAnchorX = 31*215/230/2, iconAnchorY = 16),
        ChinaResourcesIcon <- makeIcon(iconUrl = "https://cdn.countryflags.com/thumbs/china/flag-800.png", iconWidth = 31*215/230, 
                                       iconHeight = 31, iconAnchorX = 31*215/230/2, iconAnchorY = 16),
        HeinekenIcon <- makeIcon(iconUrl = "https://cdn.countryflags.com/thumbs/netherlands/flag-800.png", iconWidth = 31*215/230, 
                                 iconHeight = 31, iconAnchorX = 31*215/230/2, iconAnchorY = 16),
        CarlsbergIcon <- makeIcon(iconUrl = "https://cdn.countryflags.com/thumbs/denmark/flag-800.png", iconWidth = 31*215/230, 
                                  iconHeight = 31,iconAnchorX = 31*215/230/2, iconAnchorY = 16),
        MolsonIcon <- makeIcon(iconUrl = "https://cdn.countryflags.com/thumbs/united-kingdom/flag-800.png", iconWidth = 31*215/230, 
                               iconHeight = 31, iconAnchorX = 31*215/230/2, iconAnchorY = 16))


#Making a dataframe with the coordinates of the Headquarters
breweries <- data.frame(name = c("Anheuser-Busch", "Heineken", "China Resources", "Carlsberg", "Molson Coors"),
                        lat = c(38.597214, 52.357827, 31.299727, 55.664102, 52.804566),
                        lng = c(-90.209132, 4.892018, 120.677774, 12.536231, -1.626800), 
                        country= c("United States", "Netherlands", "China", "Denmark", "UK" ))


#Creating the ma with custom icons
Beer_map<- leaflet() %>% addTiles() %>% addMarkers(icon=Icons,
                                        lat= c(38.597214,31.299727 ,52.357827,  55.664102, 52.804566), 
                                        lng= c(-90.209132,120.677774 ,4.892018,  12.536231, -1.626800), 
                                        popup= c("Anheuser-Busch", "Heineken", "China Resources", "Carlsberg", "Molson Coors")) %>% 
                                        addLegend(labels = c("Anheuser-Busch", "Heineken", "China Resources", "Carlsberg", "Molson Coors"), 
                                        colors= c("Anheuser-Busch", "Heineken", "China Resources", "Carlsberg", "Molson Coors")) 

Beer_map