• R/O
  • SSH

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

File Info

Révision 6802b53f4d9935e1e945f82ad885f4751502e9b2
Taille 8,429 octets
l'heure 2022-06-08 21:40:14
Auteur Lorenzo Isella
Message de Log

I improved some tables and plots.

Content

---
output: word_document
---


```{r, scoreboard, echo=FALSE, eval=TRUE}

options( scipen = 16 )

options(tidyverse.quiet = TRUE)
suppressWarnings(suppressMessages(library(janitor)))
suppressWarnings(suppressMessages(library(viridis)))
suppressWarnings(suppressMessages(library(scales)))
## suppressWarnings(suppressMessages(library(treemap)))
suppressWarnings(suppressMessages(library(flextable)))

library(tidyverse, warn.conflicts = FALSE)
library(janitor)
library(viridis)
library(scales)
## library(treemap)
library(stringi)
library(flextable)

source("/home/lorenzo/myprojects-hg/R-codes/stat_lib.R")

sel_ms <- state

country <- iso_map_eu27 %>%
    filter(iso2==sel_ms) %>%
    pull(country)
    
fn <- paste("./intermediate_files/table_data_word_", sel_ms, ".RDS", sep="")


df <- readRDS(fn)

df_dec <- readRDS("./intermediate_files/decisions_MS.RDS")

n_dec <- df_dec %>%filter(member_state_2_letter_code==sel_ms,
                          legal_basis!="Total")%>%
    pull(n_decisions) %>% sum


n_am <- readRDS("./intermediate_files/number_amendments.RDS") %>%
    filter( member_state_of_amendment  ==sel_ms) %>%
    pull(n_amendments)


df_mes <- readRDS("./intermediate_files/covid_measures_MS.RDS")  

n_mes <- df_mes %>% 
    filter( member_state_2_letter_code==sel_ms,
           legal_basis!="Total") %>%
    pull(n_measures) %>%
    sum

list_mes <- df_mes %>%
    filter(n_measures!=0,
           legal_basis!="Total",
           member_state_2_letter_code==sel_ms
           ) %>%
    arrange(desc(n_measures)) %>%
    mutate(text=paste(n_measures, " under ", legal_basis, sep="")) %>%
    pull(text) %>%
    paste(collapse=", ")

budget_ini <- readRDS("./intermediate_files/budget_complete.RDS") 


budget_sel <- budget_ini %>%
    filter(member_state_2_letter_code==sel_ms)

## budget_ms <- budget_ini %>% 
##     filter(member_state_2_letter_code==sel_ms) %>%
##     pull(budget)  %>%
##     divide_by(1e3) 



budget_eu <- budget_ini %>%
    filter(member_state_2_letter_code=="Total") %>% 
    pull(budget)  %>%
    divide_by(1e6) %>%
    round(digits=2)

## ratio_budget_ms <- budget_ms %>%
##     divide_by(budget_eu) %>%
##     multiply_by(100) %>%
##     round(digits=1)

## budget_eu <- budget_eu %>%
##     divide_by(1e3) %>%
##     round(digits=2)

## budget_ms <- budget_ms%>%
##     round(digits=1)


budget_sector_ini <- readRDS("./intermediate_files/budget_sector_MS.RDS")

budget_sector <- budget_sector_ini %>%
    filter(member_state_2_letter_code==sel_ms,
           beneficary_sector!="Total") %>%
    arrange(desc(budget)) %>%
    mutate(budget=round(budget/1e3,1),
           share=round(share*100,2)) %>%
    find_text_replace("\\&", "and") %>%
    find_text_replace("NPO", "non-profit organizations")


budget_type_ini <- readRDS("./intermediate_files/budget_type_MS.RDS")

budget_type <- budget_type_ini %>%
    filter(member_state_2_letter_code==sel_ms,
           beneficary_type!="Total") %>%
    arrange(desc(budget)) %>%
    mutate(budget=round(budget/1e3,1),
           share=round(share*100,2)) %>%
    find_text_replace("\\&", "and") %>%
    find_text_replace("(?i)All sizes", "companies of any size") %>%
    find_text_replace("(?i)SMEs and Large", "SMEs and large enterprises") %>%
    find_text_replace("(?i)Micro and SME", "SMEs and micro enterprises")  %>%
    find_text_replace("(?i)Micro and small", "micro and small enterprises") %>% 
    find_text_replace("(?i)excl.", "excluding") %>% 
    find_text_replace("(?i)Medium.", "medium") %>% 
    find_text_replace("(?i)Ad", "ad") 

duration_ini <- readRDS("./intermediate_files/duration_stat_MS.RDS")

duration <- duration_ini %>%
    filter(member_state_2_letter_code==sel_ms) %>%
    mutate(mean_duration=as.numeric(round(mean_duration,0)),
           median_duration=as.numeric(round(median_duration,0)))


decisions_time_budget_ini <- readRDS("./intermediate_files/decisions_budget_time.RDS")

decisions_time <- decisions_time_budget_ini %>%
    filter(member_state_2_letter_code==sel_ms) 

decisions_n <- decisions_time %>%
    arrange(desc(n_decisions))


decisions_budget <- decisions_time %>%
    arrange(desc(budget))


```



* The Commission has so far taken `r n_dec` decisions (and `r n_am`
  amendment decisions) approving `r n_mes` State aid measures for
  `r country`, `r list_mes`.
  
* The total amount of Covid-19 aid approved for `r country` is
  estimated around €`r budget_sel%>%pull(budget)%>%divide_by(1e3) %>% round(1)` billion, corresponding to `r budget_sel%>%pull(share)%>%multiply_by(100)%>%round(1)`%
 of the total €`r budget_eu` trillion of total State aid approved for
  the EU27 and to 
  `r budget_sel%>%pull(gdp)%>%multiply_by(100)%>%round(1)`% of the GDP of
  `r country` in 2019.
* Around `r budget_sector$share[1]`% of the total budget of the State
  aid measures approved for `r country` (€`r budget_sector$budget[1]`
  billion) is directed to `r tolower(budget_sector$beneficary_sector[1])`
  followed by about `r budget_sector$share[2]`% toward
  `r tolower(budget_sector$beneficary_sector[2])` and about
  `r budget_sector$share[3]`%  is destined to
  `r tolower(budget_sector$beneficary_sector[3])`.
 * Around `r budget_type$share[1]`% of the total budget of the State
  aid measures approved for `r country`
  is directed to `r (budget_type$beneficary_type[1])`
  and  `r budget_type$share[2]`% toward
  `r (budget_type$beneficary_type[2])`. Around
  `r budget_type$share[3]`%  is destined to
  `r (budget_type$beneficary_type[3])`.
* The average case assessment duration is around
`r duration$mean_duration`  calendar days (median:
`r duration$median_duration` days).
* The month when the highest number of decisions were approved was
`r decisions_n$date_easy[1]` 
(`r (decisions_n$n_decisions[1])` decisions,
`r (decisions_n$share_dec[1])`% of the total approved decisions for `r country`) (see Figure below). 

```{r, echo=FALSE,fig.height = 6, fig.width = 12}
ggplot(data = decisions_time,
              aes(x = date, y = n_decisions)) +
    ## geom_point(size=2 , shape=1
    ##       , stroke=2
    ##         ) +
    ## geom_line(size=2)+
    geom_col()+
    my_ggplot_theme2("right")+
    ## facet_wrap(~ member_state_2_letter_code, nrow=7, scales = "free_y" )+

    ## coord_cartesian(ylim = c(0, 1)) +

    scale_y_continuous() +
    scale_x_date(breaks = "1 month",
                 date_labels = "%b\n%Y",
                 expand=c(0.01,0.01),
                 guide = guide_axis(n.dodge = 2))+    
    ylab("Number of approved decisions")+
    xlab(NULL)
```

* The month when the highest allocated budget was approved was 
`r decisions_budget$date_easy[1]` 
(€`r (decisions_budget$budget[1]/1e3)` billion,
`r (decisions_budget$share_budget[1])`% of the total approved budget
for `r country`) (see Figure below). 

```{r, echo=FALSE,fig.height = 6, fig.width = 12}

ggplot(data = decisions_time,
              aes(x = date, y = budget/1e3)) +
    ## geom_point(size=2 , shape=1
    ##       , stroke=2
    ##         ) +
    ## geom_line(size=2)+
    geom_col()+
    my_ggplot_theme2("right")+
    ## facet_wrap(~ member_state_2_letter_code, nrow=7, scales = "free_y" )+

    ## coord_cartesian(ylim = c(0, 1)) +

    scale_y_continuous() +
    scale_x_date(breaks = "1 month",
                 date_labels = "%b\n%Y",
                 expand=c(0.01,0.01),
                 guide = guide_axis(n.dodge = 2))+
    ylab("Approved budget (€ billion)")+
    xlab(NULL)

```


* Below we list the State aid cases approved for `r country`.
```{r, table1, echo=FALSE, eval=TRUE}
df %>%
    flextable() %>%
    ## add_header_row(values = c("some measures", "other measures") )%>%
    set_header_labels(case_reference="Case Reference",
        working_title="Working Title",
                      legal_basis="Legal Basis",
                      decision_date="Decision Date (YYYY-MM-DD)",
                      confirmed_budgets="Budgets (million €)",
                      type_of_measure="Type of Measure",
                      beneficary_sector="Beneficiary Sector",
                      beneficary_type="Beneficiary Type",
                      am_list="Amended by"   
                      ) %>%     
    theme_zebra() %>%
    theme_box() %>% 
    fontsize(part = "all", size = 8)  %>%
    font(part="all", fontname = "Verdana") %>% 
    colformat_double(big.mark = " ") %>% 
    ## autofit() ## %>%
    width(width = c(.8,1,.8,.8,1,1,1,.8,1))
```