-
Notifications
You must be signed in to change notification settings - Fork 0
/
R20190317
64 lines (35 loc) · 1.66 KB
/
R20190317
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#if (!require("leaflet")) install.packages("leaflet", repos="https://cran.cnr.berkeley.edu/", dependencies = TRUE)
#if (!require("rgdal")) install.packages("rgdal", repos="https://cran.cnr.berkeley.edu/", dependencies = TRUE)
#if (!require("rtweet")) install.packages("rtweet", repos="https://cran.cnr.berkeley.edu/", dependencies = TRUE)
#if (!require("htmlwidgets")) install.packages("htmlwidgets", repos="https://cran.cnr.berkeley.edu/", dependencies = TRUE)
require("htmlwidgets")
require("leaflet")
require("rgdal")
require("rtweet")
install.packages("htmlwidgets")
library(htmlwidgets)
install.packages("leaflet")
library(leaflet)
install.packages("rgdal")
library(rgdal)
install.packages("rtweet")
library(rtweet)
setwd('C:/R0317')
getwd()
GDP<-read.csv('GDP growth.csv',encoding = "UTF-8")
#districts <- readOGR("./ne_50m_admin_0_countries/ne_50m_admin_0_countries.shp",layer = "ne_50m_admin_0_countries",
# GDAL1_integer64_policy = TRUE,TM_WORLD_BORDERS-0.3.shp
districts <- readOGR("TM.shp",GDAL1_integer64_policy = TRUE,layer = "Hong_Kong_18_Districts", GDAL1_integer64_policy = TRUE)
districts
pop <- read.csv("district_pop.csv")
pop
fix(GDP)
districts$ENAME
districts$GDP <- GDP$X2015..YR2015.[match(as.character(districts$ENAME),GDP$Country.Code)]
#districts$pop <- GDP$percentage[match(as.character(districts$ENAME),pop$district)]
m <- leaflet()
m <- addTiles(m)
pal <- colorNumeric(palette="Greens",domain=districts$pop)
m <- addPolygons(m,data=districts,weight = 1,popup=~ENAME,color = ~pal(districts$pop))
m <- addLegend(m, "bottomright", pal = pal, values = districts$pop, title = "GDP growth %", labFormat = labelFormat(suffix = "%"), opacity = 0.75)
m