Data comes from here http://data.world/education/university-rankings-2017 from this site you can download table with names of the universities, their description and fees and tuition.

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

Table has names and location but for use it in leaflet package we need latitude and longtitude. Google maps api can help with the coordinates of the objects. In special RgoogleMaps package there is function getGeoCode but it can’t be used because for now googlle maps api requires APIkey. Because of this code for this function was modified to meet google requirements. The code is as follows:

getGeo <- function(gcStr, APIkey)
{
        library("RJSONIO") #Load Library
        gc <- sub(" ", "+", gcStr)
        connectStr <- paste('https://maps.googleapis.com/maps/api/geocode/json?address=', gc, "&key=", APIkey, sep="") 
        con <- url(connectStr)
        data.json <- fromJSON(paste(readLines(con), collapse=""))
        close(con)
        #Flatten the received JSON
        data.json <- unlist(data.json)
        lat <- data.json["results.geometry.location.lat"]
        lng <- data.json["results.geometry.location.lng"]
        gcodes <- data.frame(Lat = lat, Lng = lng, Name = gcStr)
        return (gcodes)
}

To get coordinates for every row of our table I use custom function with “for” loop

coord <- tablecodes(data, APIkey)
fulldata <- merge(data, coord)

Now we can create a map with top Us universities

library(leaflet)
map <- addTiles(leaflet())
popup <- paste(fulldata$Name, "<br/>", "Rank = ", as.character(fulldata$Rank), "<br/>", "Tuition: ", fulldata$Tuition.and.fees, sep="")

addAwesomeMarkers(map, lng = as.numeric(as.character(fulldata$Lng)), lat = as.numeric(as.character(fulldata$Lat)), popup = popup, clusterOptions = 1, label = fulldata$Name)