-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglobal.R
43 lines (36 loc) · 1.19 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
library(shiny)
library(shinydashboard)
library(dashboardthemes)
library(shinycustomloader)
library(RColorBrewer)
library(leaflet)
library(rnaturalearth)
library(sp)
library(DT)
library(dplyr)
library(readr)
## load data
final_table <- readRDS("data/consumption-CO2emissions-data.rds")
# tidy up
final_table <- final_table %>%
mutate(consumption = parse_number(consumption),
co2_emmission = readr::parse_number(co2_emmission))
# country name cleaning
final_table$country[final_table$country == "USA"] <- "United States"
final_table$country[final_table$country == "Congo"] <- "Dem. Rep. Congo"
final_table$country[final_table$country == "Czech Republic"] <- "Czech Rep."
final_table$country[final_table$country == "Guinea"] <- "Eq. Guinea"
final_table$country[final_table$country == "South Korea"] <- "Korea"
final_table$country[final_table$country == "Taiwan. ROC"] <- "Taiwan"
## data matching
countries <- rnaturalearth::ne_countries()
names(countries)[names(countries) == "name"] <- "country"
# add consumption & emission data to polygon data
map <-
sp::merge(
countries,
final_table,
duplicateGeoms = TRUE
)
# remove missing values
map2 <- map[!is.na(map@data$food_category), ]