Number of Schools by Country

geo1=JC%>%group_by(Country)%>%summarize(Count=length(City))

#merg to geo-table
locs1=geo1

#add country code for tiles maps
locs1$iso_a3=as.factor(countrycode(geo1$Country,"country.name","iso3c"))

#Map Data   
url <- "http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip"

folder <- getwd() #set a folder where to download and extract the data
file <- basename(url) 
 download.file(url, file)
 unzip(file, exdir = folder)
    
#And read it with rgdal library
world <- readOGR(dsn = folder, 
                 layer = "ne_50m_admin_0_countries",
                 encoding = "UTF-8",
                 verbose = FALSE)
#setup to merge with "World geomap"
locs1=data.frame(locs1)

#world <- sp::merge(world,locs2, by="iso_a3")
world <- merge(world, locs1,
               by.x = "iso_a3",
               by.y = "iso_a3",
               sort = FALSE)

#world@data$iso_a3
#Colour palette. Check ?colorQuantile and ?RColorBrewer for more options
pal <- colorNumeric(palette = "Blues",domain = locs1$Count)

#Pop up: The info displayed when click on a country
world_popup <- paste(world$admin, 

                      ", Number of Schools:", 

                      world$Count)
#Tiles coming from stamen.com
tiles <- "http://{s}.tile.stamen.com/toner-lite/{z}/{x}/{y}.png"
attribution <- 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Map data by <a href="http://www.naturalearthdata.com/">Natural Earth</a>.'
leaflet(data = world) %>% 
  addTiles(urlTemplate = tiles,  
         attribution = attribution) %>%
  setView(0, 0, zoom = 2) %>% 
  addPolygons(fillColor = ~pal(world$Count), 
              fillOpacity = 1, 
              color = "#000000", 
              weight = 1, popup = world_popup) %>%
    addLegend("bottomright", pal = pal, values =~Count, 
              title ="Number of Schools", opacity = 1)

Locations of Schools in the World

###NEW Table for ggmap function
#geo2=JC
#geo2=geo2[-c(1:15),c(8,10)]%>%group_by(City, Country)%>%summarize(Count=length(City))

### combining the city and country can help with the geocoding of the city, which we do next.
#geo2$CityCountry=paste(geo2$City,geo2$Country,sep=", ")  

#locs2=geocode(geo2$CityCountry, output = c("latlon"),
#source = c("google"), messaging = FALSE, sensor = FALSE,
#override_limit = FALSE)

#geo2$lat=locs2$lat
#geo2$lon=locs2$lon

#save(geo2,file="geo2.csv")

geo2 = read_excel("geo2.xlsx")

geo2$popup=paste("<table><tr><td>City:", geo2$City,"<br>Country:",geo2$Country, "<br>Number of Schools:", geo2$Count,"</td></tr></table>")

leaflet(geo2)%>%
  addProviderTiles("CartoDB.Positron") %>%
     setView(0, 0, zoom = 2) %>%
  addCircles(stroke=FALSE, fillOpacity = .5, color="blue", radius=~Count*50000,popup=~popup)
## Assuming 'long' and 'lat' are longitude and latitude, respectively

#saveWidget(JCSchools,"JCSchools.html", selfcontained = TRUE)

Mean (Student vs Staff) Ratio By Country

geo3=JC%>%group_by(Country)%>%summarize(Mean=mean(Student.Staff.Ratio))

dimple(data = geo3, x="Country", y= "Mean", type = "bar") %>%
  yAxis( orderRule="Country") %>%
  add_title( "Student vs. Staff Ratio by Country") %>%
  set_bounds( x="10%", y="1%", width="80%",height="80%")