#setwd("F:/Business/489/Geographic Assignment")
tallb=read.csv("tallestbuildings.csv")
library(dplyr)
##
## 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(tidyr)
library(ggplot2)
library(leaflet)
library(countrycode)
library(ggmap)
library(readxl)
library(choroplethr)
library(choroplethrMaps)
library(RColorBrewer)
library(rgdal)
## Loading required package: sp
## rgdal: version: 1.1-1, (SVN revision 572)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
## Path to GDAL shared files: C:/Users/Danny/Documents/R/win-library/3.2/rgdal/gdal
## GDAL does not use iconv for recoding strings.
## Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
## Path to PROJ.4 shared files: C:/Users/Danny/Documents/R/win-library/3.2/rgdal/proj
## Linking to sp version: 1.2-1
library(htmlwidgets)
library(googleVis)
##
## Welcome to googleVis version 0.5.10
##
## Please read the Google API Terms of Use
## before you start using the package:
## https://developers.google.com/terms/
##
## Note, the plot method of googleVis will by default use
## the standard browser to display its output.
##
## See the googleVis package vignettes for more details,
## or visit http://github.com/mages/googleVis.
##
## To suppress this message use:
## suppressPackageStartupMessages(library(googleVis))
countcity = tallb %>% group_by(City)%>% summarise(count=length(City))
count_city= countcity %>% separate(City, c("City", "Country"), sep="\\(")
count_city$Country = gsub(")", "", as.character(count_city$Country))
count_city$Country = countrycode(count_city$Country, "iso2c", "country.name")
count_city$CityCountry=paste(count_city$City,count_city$Country,sep=", ")
locscountcitycountry=read_excel("City Long Lat.xlsx")
regionvalue=read_excel("RegionValue.xlsx")
map1=get_map(location=c(-92.1333,10), maptype="terrain", source="google", zoom=3)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=10,-92.1333&zoom=3&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
static1=ggmap(map1)
static1=static1+geom_point(data=locscountcitycountry, aes(Longitude, Latitude, size=locscountcitycountry$Count))+scale_size(range=c(5,20))
print(static1)
## Warning: Removed 33 rows containing missing values (geom_point).

map2=get_map(location=c(20.4833,41.9), maptype="terrain", source="google", zoom=3)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=41.9,20.4833&zoom=3&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
static2=ggmap(map2)
static2=static2+geom_point(data=locscountcitycountry, aes(Longitude, Latitude, size=locscountcitycountry$Count))+scale_size(range=c(5,20))
print(static2)
## Warning: Removed 32 rows containing missing values (geom_point).

map3=get_map(location=c(120,0), maptype="terrain", source="google", zoom=3)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=0,120&zoom=3&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
static3=ggmap(map3)
static3=static3+geom_point(data=locscountcitycountry, aes(Longitude, Latitude, size=locscountcitycountry$Count))+scale_size(range=c(5,20))
print(static3)
## Warning: Removed 15 rows containing missing values (geom_point).

leaflet() %>% addTiles() %>% addCircleMarkers(data=locscountcitycountry, popup=~City, radius=~Count*.5)
## Assuming 'Longitude' and 'Latitude' are longitude and latitude, respectively
country_choropleth(regionvalue)
## Warning in self$bind(): The following regions were missing and are being
## set to NA: afghanistan, angola, azerbaijan, moldova, madagascar, mexico,
## macedonia, mali, myanmar, montenegro, mongolia, mozambique, mauritania,
## burundi, malawi, namibia, france, niger, nigeria, nicaragua, netherlands,
## norway, nepal, belgium, new zealand, oman, pakistan, panama, peru,
## philippines, papua new guinea, poland, north korea, benin, portugal,
## paraguay, israel, romania, rwanda, western sahara, sudan, burkina
## faso, south sudan, senegal, solomon islands, sierra leone, el salvador,
## somaliland, somalia, republic of serbia, suriname, slovakia, bangladesh,
## slovenia, sweden, swaziland, syria, chad, togo, tajikistan, turkmenistan,
## east timor, bulgaria, trinidad and tobago, tunisia, turkey, united
## republic of tanzania, uganda, ukraine, uruguay, uzbekistan, the bahamas,
## venezuela, vanuatu, yemen, south africa, zambia, zimbabwe, bosnia and
## herzegovina, belarus, albania, belize, bolivia, brazil, brunei, bhutan,
## botswana, central african republic, switzerland, ivory coast, cameroon,
## democratic republic of the congo, republic of congo, colombia, costa
## rica, cuba, northern cyprus, cyprus, argentina, czech republic, germany,
## djibouti, denmark, dominican republic, algeria, ecuador, egypt, eritrea,
## spain, armenia, estonia, ethiopia, finland, fiji, gabon, georgia, ghana,
## antarctica, guinea, gambia, guinea bissau, equatorial guinea, greece,
## guatemala, guyana, honduras, croatia, haiti, hungary, indonesia, india,
## ireland, iran, iraq, iceland, italy, jamaica, jordan, kazakhstan, kenya,
## kyrgyzstan, cambodia, kosovo, austria, laos, lebanon, liberia, libya, sri
## lanka, lesotho, lithuania, luxembourg, latvia, morocco

CountryCount=read_excel("CountryCount.xlsx")
# url <- "http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip"
# folder <- getwd()
# file <- basename(url)
# download.file(url, file)
# unzip(file, exdir = folder)
world <- readOGR(dsn="ne_50m_admin_0_countries.shp",
layer = "ne_50m_admin_0_countries",
encoding = "UTF-8",
verbose = FALSE)
countryleaf=data.frame(CountryCount)
world <- merge(world, countryleaf,
by.x = "iso_a2",
by.y = "iso_a2",
sort = FALSE)
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>.'
world$popup=paste(world$name,", Number of buildings:", world$Count)
pal <- colorNumeric(palette = "Reds", domain = CountryCount$Count)
leaflet(data=world) %>% addTiles(urlTemplate=tiles, attribution=attribution) %>% setView(0,0,zoom=2) %>% addPolygons(fillColor = ~pal(world$Count), fillOpacity = 1, color = "#00000", popup=~popup,weight=1)