修订版 | d253bdeb31b3f2c3d652f353954c619e3128eb9d (tree) |
---|---|
时间 | 2021-09-16 18:50:16 |
作者 | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
I modified both codes to deal better with NACE 1-digit categories.
@@ -4,6 +4,8 @@ | ||
4 | 4 | library(janitor) |
5 | 5 | library(openxlsx) |
6 | 6 | library(lubridate) |
7 | +library(stringr) | |
8 | +library(stringi) | |
7 | 9 | |
8 | 10 | source("/home/lorenzo/myprojects-hg/R-codes/stat_lib.R") |
9 | 11 |
@@ -24,7 +26,13 @@ | ||
24 | 26 | |
25 | 27 | } |
26 | 28 | |
27 | - | |
29 | + | |
30 | + | |
31 | + | |
32 | +nace <- read_excel("nace_codes.xlsx") %>% | |
33 | + mutate(code=substrLeft(description,1)) | |
34 | + | |
35 | + | |
28 | 36 | |
29 | 37 | df <- df_ini %>% |
30 | 38 | clean_tam() %>% |
@@ -58,7 +66,11 @@ | ||
58 | 66 | find_text_replace("\\(leasing subsidy","leasing subsidy") %>% |
59 | 67 | find_text_replace("leasing subsidy\\)","leasing subsidy") %>% |
60 | 68 | find_text_replace("feed-in tariffs","feed-in tariff") %>% |
61 | - find_text_replace("tarriif","tariff") | |
69 | + find_text_replace("tarriif","tariff") %>% | |
70 | + mutate(macro_sector=substrLeft(beneficiary_sector, 1)) %>% | |
71 | + left_join(y=nace, by=c("macro_sector"="code")) %>% | |
72 | + select(-macro_sector) %>% | |
73 | + rename("macro_sector"="description") | |
62 | 74 | |
63 | 75 | |
64 | 76 |
@@ -103,10 +103,16 @@ | ||
103 | 103 | unique %>% |
104 | 104 | sort |
105 | 105 | |
106 | -beneficiaries_sector <- df_ini$beneficiary_sector %>% | |
106 | +## beneficiaries_sector <- df_ini$beneficiary_sector %>% | |
107 | +## unique %>% | |
108 | +## sort | |
109 | + | |
110 | + | |
111 | +beneficiaries_sector <- df_ini$macro_sector %>% | |
107 | 112 | unique %>% |
108 | 113 | sort |
109 | 114 | |
115 | + | |
110 | 116 | truncated_beneficiaries_sector <- beneficiaries_sector %>% |
111 | 117 | shiny_wrap(len_truncation) |
112 | 118 |
@@ -250,13 +256,15 @@ | ||
250 | 256 | compound_data <- reactive({ |
251 | 257 | |
252 | 258 | df_ini %>% filter(## is_co_finance %in% input$cofinanced, |
253 | - year %in% input$year_award, | |
254 | - beneficiary_country %in% input$country , | |
255 | - beneficiary_type %in% input$beneficiary_type, | |
256 | - beneficiary_sector %in% input$beneficiary_sector, | |
257 | - instrument_type %in% input$instrument_type, | |
259 | + year %in% input$year_award, | |
260 | + beneficiary_country %in% input$country , | |
261 | + beneficiary_type %in% input$beneficiary_type, | |
262 | + ## beneficiary_sector %in% input$beneficiary_sector, | |
263 | + macro_sector %in% input$beneficiary_sector, | |
264 | + | |
265 | + instrument_type %in% input$instrument_type, | |
258 | 266 | ## main_procedure_type_code %in% input$procedure_code, |
259 | - aid_objective %in% input$objectives) | |
267 | + aid_objective %in% input$objectives) | |
260 | 268 | |
261 | 269 | |
262 | 270 | }) |
@@ -420,7 +428,7 @@ | ||
420 | 428 | output$downloadViz <- downloadHandler( |
421 | 429 | filename = "plot.png" , |
422 | 430 | content = function(file) { |
423 | - ggsave(myplot(), filename = file, width=12, height=6) | |
431 | + ggsave(myplot(), filename = file, width=12, height=12) | |
424 | 432 | |
425 | 433 | }) |
426 | 434 |