Simple Mapping with Leaflet

The interactive map of Poland below was created using a leaflet package. The map as well as a whole code are presented below.

Code:

#Packages
library("dplyr")
library("ggplot2")
library("plyr")
library('rgdal')
library('leaflet')
#Read a shapfile
voi <- readOGR('data', 'voivodeship',verbose=FALSE)
#Create a legend
voi_popup <- paste0("Woivodeship ", voi$NAZ, "<br>",
                    voi$NAZ_ENG, "<br>",
                    "<br><strong>GDP per capita [PLN]: </strong>", 
                    voi$PKB_percap,
                    "<br><strong>GDP in percent [%]: </strong>",
                    voi$pkb_proc)
#Choose a color palette
binpal <- colorBin("Blues", voi$pkb_proc, 4, pretty = TRUE)
# Read a point data from a shape file (cities)
cities <- readOGR('data', 'cities', verbose=FALSE)
cities_popup <- paste0( "<strong>Size rank: </strong>", cities$id,
                        "<br><strong>City:</strong> ",cities$Miasta_eng,
                        "<br><strong>Population: </strong>", 
                        cities$Ludnosc)

# Pull out coordinates of points and insert them into a table
cities@data$lng <- cities@coords[,1]
cities@data$lat <- cities@coords[,2]
# Create a map
leaflet(voi) %>% addPolygons(stroke = FALSE, smoothFactor = 0.2, fillOpacity = 1,
                             color = ~binpal(pkb_proc), popup=voi_popup) %>% 
  addPolylines(color="black", opacity=1, weight=1) %>% 
  addLegend("bottomleft", pal = binpal, values = ~pkb_proc,
            title = "GDP per capita [%]") %>% addProviderTiles("CartoDB.Positron") %>% 
# Adjust points on the map  
  addCircles(lng=cities@data$lng, lat=cities@data$lat, 
                 popup=cities_popup, color='red', weight=7)  %>% 
# Adjust a legend
  addLegend("bottomleft", colors= "red", labels="Cities", title="The biggest cities")