-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobal.R
56 lines (30 loc) · 1.11 KB
/
global.R
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
library(jsonlite)
library(geojsonio)
library(dplyr)
library(leaflet)
library(imputeMissings)
# setwd("/Users/Andy_Lee/R/Code/project")
# From http://data.okfn.org/data/datasets/geo-boundaries-world-110m
geojson<- geojsonio::geojson_read("countries.geojson",what = "sp")
Country <-as.character(geojson$admin)
pop_est <-as.numeric(as.character(geojson$pop_est))
#Segregate Country and Popdata from list
Df<-cbind(Country,pop_est)
Df1<-as.data.frame(Df)
Df1$pop_est<-as.numeric(as.character(Df1$pop_est))
Df1$Country<-as.character(Df1$Country)
arrange(Df1,Country)
cat(paste(head(Df1)))
#Read csv file
dataAnalytics<-read.csv("countries-aggregated.csv",na.strings = NA,fill = NA)
dataAnalytics<-impute(dataAnalytics)
colSums(is.na(dataAnalytics))
arrange(Df1,Country)
#filter relevant data
df1<-dataAnalytics %>%filter(Date=="2020-03-27")%>%group_by(Country)
#cat(paste(head(df1$Country)))
CountryData<-left_join(Df1,df1,by="Country")
#cat(paste(head(CountryData)))
# Add the now-styled GeoJSON object to the map
bins<-seq(0,1,by=0.1)
pal <- colorBin(palette = c("green","yellow","red"),domain = c(0,100),bins = bins)