Jaune pondération

Auteur·rice

Edmond Noack

1- Package

knitr::opts_chunk$set(dev = "ragg_png")
library(dplyr)
library(tidyr)
library(janitor) 
library(ggplot2)
# library(extrafont)
library(arrow)
library(gt)
options(scipen = 999)

2- Création base

poids <- read_parquet("P:/production_efe_2024/data/base_intermediaire/quatre_poids.parquet")



bds24 <- read_parquet("P:/production_efe_2024/data/base_externe/bds2024.parquet") 

data24 <- read_parquet("P:/production_efe_2024/data/base_externe/base_2024_jaune_vf.parquet") %>% 
  mutate(formatrice = if_else(b1a == "1"| b1b == "1",1,0)) %>% 
  select(sirus_id, weight, formatrice,
         a2tot,  a6, a5, a4, 
         c1tot, c3tot, c4af, c4hs, ind_c1tot, ind_c3tot, ind_c4af, ind_c4hs,
         c7sub, ind_c7sub,
         b5am, b5ad, b5amcdd, b5acm, b5abm,
         b6bsom,  b6dsom, ind_b6bsom, ind_b6dsom,
         b1cflag) %>% 
  mutate(annee = "2024") %>% 
  left_join(bds24, by="sirus_id")


data <- poids |> 
  left_join(data24, by="sirus_id") |> 
  filter(annee=="2024")



data <- data %>% 
  rename(secteur_jaune=secteur12_2024) |> 
  mutate(
    taille_jaune = case_when(
      a2tot < 50 ~ "Moins de 50 salariés",
      a2tot > 49 & a2tot < 250 ~ "De 50 à 249 salariés",
      a2tot > 249 & a2tot < 1000 ~ "De 250 à 999 salariés",
      a2tot >= 1000 ~ "1000 salariés ou plus"
    ),
    taille_jaune = factor(taille_jaune, levels = c(
      "Moins de 50 salariés",
      "De 50 à 249 salariés",
      "De 250 à 999 salariés",
      "1000 salariés ou plus")
    ),
    secteur_jaune_lib =  case_when( 
      secteur_jaune == "01" ~ "Agriculture",
      secteur_jaune == "02" ~ "Industrie",
      secteur_jaune == "03" ~ "Construction",
      secteur_jaune == "04" ~ "Commerce et réparation d'automobiles",
      secteur_jaune == "05" ~ "Transports et entreposage",
      secteur_jaune == "06" ~ "Hébergement et restauration",
      secteur_jaune == "07" ~ "Information et communication",
      secteur_jaune == "08" ~ "Activités financières et d'assurance",
      secteur_jaune == "09" ~ "Activités immobilières et scientifiques",
      secteur_jaune == "10" ~ "Services administratifs et de soutien",
      secteur_jaune == "11" ~ "Arts et spectacles",
      secteur_jaune == "12" ~ "Enseignement et santé"
    ),
    secteur_jaune_lib = factor(secteur_jaune_lib, levels = c(
      "Agriculture",
      "Industrie",
      "Construction",
      "Commerce et réparation d'automobiles",
      "Transports et entreposage",
      "Hébergement et restauration",
      "Information et communication",
      "Activités financières et d'assurance",
      "Activités immobilières et scientifiques",
      "Services administratifs et de soutien",
      "Arts et spectacles",
      "Enseignement et santé")
    ),
    tertiaire = if_else(!secteur_jaune %in% c("01","02","03"), 1, 0)
  )



# NC & NR ---------------------------------------------------------------------

data <- data %>% 
  mutate(
    across(c(b6dsom,b6bsom, b5am, b5abm, b5acm, c7sub, c3tot, c4hs, c4af),
           ~ if_else(. %in% c(99999999998,
                              99999999999,
                              9999999999,
                              9999999998), 0, .)
    ),
    c1tot = if_else(c1tot == 999998, 0, c1tot),
    b1cflag = if_else(b1cflag %in% c("8","9"), "0", b1cflag),
    b1cflag = as.numeric(b1cflag)
  )

3 - Calcul indicateur

3.1 Dépenses et heures de formation

data <- data %>% 
  mutate(
    PAC = (a5/a4)*c3tot,
    dep_directes = c7sub + PAC,
    dep_interm = b5am + b5ad + b5amcdd + b5abm + b5acm,
    remb_aides = b6bsom + b6dsom,
    
    # NB on a accepté des cas de c4hs + c4af > c3tot (avec c4hs < c3tot & c4af < c3tot)
    # car certaines formations pouvaient potentiellement tomber dans les deux catégories
    # mais il faut le prendre en compte ici
    heures_oblig = if_else(c4hs + c4af > c3tot, c3tot, c4hs + c4af)
  )

3.1.1 Tableau 1 : Dépenses

# Tableau 1 --------------------------------------------------------------------
# Série: dépenses par année

tableau1_old <- data %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_old),
    tot_dep_interm =  sum(dep_interm*poids_old),
    tot_remb_aides = sum(remb_aides*poids_old),
    tot_ms = sum(a6*poids_old)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes,tot_ms),
           ~ ./1e9
    )
  ) 


tableau1_inter <- data %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_inter),
    tot_dep_interm =  sum(dep_interm*poids_inter),
    tot_remb_aides = sum(remb_aides*poids_inter),
    tot_ms = sum(a6*poids_inter)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes,tot_ms),
           ~ ./1e9
    )
  )


tableau1_new <- data %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new),
    tot_dep_interm =  sum(dep_interm*poids_new),
    tot_remb_aides = sum(remb_aides*poids_new),
    tot_ms = sum(a6*poids_new)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes,tot_ms),
           ~ ./1e9
    )
  ) 

tableau1_new_sans_icarus <- data %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new_sans_icarus),
    tot_dep_interm =  sum(dep_interm*poids_new_sans_icarus),
    tot_remb_aides = sum(remb_aides*poids_new_sans_icarus),
    tot_ms = sum(a6*poids_new_sans_icarus)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes,tot_ms),
           ~ ./1e9
    )
  ) 
tableau1 <- bind_rows(tableau1_old |> mutate(poids="old"),
                      tableau1_inter |> mutate(poids="inter"),
                      tableau1_new_sans_icarus |> mutate(poids="new_sans_icarus"),
                      tableau1_new |> mutate(poids="new") )


tableau1 <- tableau1 |> 
  select(poids,everything()) |> 
  rename(ponderation=poids)
tableau1 <- tableau1 |> 
    mutate(
    ponderation = recode(ponderation,
                         old = "Ancien",
                         inter = "Intermédiaire",
                         new_sans_icarus = "Nouveau sans Icarus",
                         new = "Nouveau")
  )

gt_table1 <- tableau1 |>
  gt(rowname_col = "ponderation") |>

  # Titre et sous-titre
  tab_header(
    title = md("**Dépenses et remboursements – EFE 2024**"),
    subtitle = md("Comparaison pondérations anciennes, intermédiaires et nouvelles")
  ) |>

  # Labels des colonnes en toutes lettres
  cols_label(
    tot_dep_directes = "Tot. Dép. Directes",
    tot_dep_interm = "Tot. Dép. Intermédiaires",
    tot_remb_aides = "Tot. Remb. Aides",
    tot_ms = "Tot. MS",
    tot_dep_brutes = "Tot. Dép. Brutes",
    tx_remb_aides = "Tx Remb. Aides",
    tot_dep_nettes = "Tot. Dép. Nettes"
  ) |>

  # Centrage de toutes les colonnes
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_column_labels(columns = everything())
  ) |>
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_body(columns = everything())
  ) |>

  # Largeur identique pour toutes les colonnes
  cols_width(
    everything() ~ px(120)
  ) |>

  # Couleurs alternées pour les lignes
  tab_style(
    style = cell_fill(color = "#7fb7df"),
    locations = cells_body(rows = ponderation == "Ancien")
  ) |>
  tab_style(
    style = cell_fill(color = "#328ccc"),
    locations = cells_body(rows = ponderation == "Intermédiaire")
  ) |>
  tab_style(
    style = cell_fill(color = "#1f6fa3"),
    locations = cells_body(rows = ponderation == "Nouveau sans Icarus")
  ) |>
  tab_style(
    style = cell_fill(color = "#0b4f6c"),
    locations = cells_body(rows = ponderation == "Nouveau")
  ) |>

  # Texte en blanc sur les couleurs
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything())
  ) |>

  tab_options(
    data_row.padding = px(8)
  )

gt_table1
Dépenses et remboursements – EFE 2024
Comparaison pondérations anciennes, intermédiaires et nouvelles
Tot. Dép. Directes Tot. Dép. Intermédiaires Tot. Remb. Aides Tot. MS Tot. Dép. Brutes Tx Remb. Aides Tot. Dép. Nettes
Ancien 16.37485 12.79964 1.198127 749.3117 29.17448 4% 27.97636
Intermédiaire 16.52724 12.84248 1.187390 752.2837 29.36972 4% 28.18233
Nouveau sans Icarus 16.33406 12.79894 1.156809 750.2195 29.13300 4% 27.97619
Nouveau 15.97291 12.74869 1.131534 747.8990 28.72160 4% 27.59007

3.1.2 Tableau 2 Dépenses et taux d’effort par taille en 2024

tableau24_old <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_old),
    tot_dep_interm =  sum(dep_interm*poids_old),
    tot_remb_aides = sum(remb_aides*poids_old),
    tot_ms = sum(a6*poids_old)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_b_old <- data %>% 
  filter(annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_old),
    tot_dep_interm =  sum(dep_interm*poids_old),
    tot_remb_aides = sum(remb_aides*poids_old),
    tot_ms = sum(a6*poids_old)
  ) %>% 
  mutate(
    taille_jaune = "Ensemble",
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_inter <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_inter),
    tot_dep_interm =  sum(dep_interm*poids_inter),
    tot_remb_aides = sum(remb_aides*poids_inter),
    tot_ms = sum(a6*poids_inter)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_b_inter <- data %>% 
  filter(annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_inter),
    tot_dep_interm =  sum(dep_interm*poids_inter),
    tot_remb_aides = sum(remb_aides*poids_inter),
    tot_ms = sum(a6*poids_inter)
  ) %>% 
  mutate(
    taille_jaune = "Ensemble",
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_new_sans_icarus <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new_sans_icarus),
    tot_dep_interm =  sum(dep_interm*poids_new_sans_icarus),
    tot_remb_aides = sum(remb_aides*poids_new_sans_icarus),
    tot_ms = sum(a6*poids_new_sans_icarus)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_b_new_sans_icarus <- data %>% 
  filter(annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new_sans_icarus),
    tot_dep_interm =  sum(dep_interm*poids_new_sans_icarus),
    tot_remb_aides = sum(remb_aides*poids_new_sans_icarus),
    tot_ms = sum(a6*poids_new_sans_icarus)
  ) %>% 
  mutate(
    taille_jaune = "Ensemble",
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_new <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new),
    tot_dep_interm =  sum(dep_interm*poids_new),
    tot_remb_aides = sum(remb_aides*poids_new),
    tot_ms = sum(a6*poids_new)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_b_new <- data %>% 
  filter(annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new),
    tot_dep_interm =  sum(dep_interm*poids_new),
    tot_remb_aides = sum(remb_aides*poids_new),
    tot_ms = sum(a6*poids_new)
  ) %>% 
  mutate(
    taille_jaune = "Ensemble",
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 
tableau24_old <- bind_rows(tableau24_old, tableau24_b_old)
tableau24_inter <- bind_rows(tableau24_inter, tableau24_b_inter)
tableau24_new_sans_icarus <- bind_rows(tableau24_new_sans_icarus, tableau24_b_new_sans_icarus)
tableau24_new <- bind_rows(tableau24_new, tableau24_b_new)

# 
# tableau24_old
# tableau24_inter
# tableau24_new
# tableau24_new_sans_icarus 
tableau24_old <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_old),
    tot_dep_interm =  sum(dep_interm*poids_old),
    tot_remb_aides = sum(remb_aides*poids_old),
    tot_ms = sum(a6*poids_old)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_b_old <- data %>% 
  filter(annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_old),
    tot_dep_interm =  sum(dep_interm*poids_old),
    tot_remb_aides = sum(remb_aides*poids_old),
    tot_ms = sum(a6*poids_old)
  ) %>% 
  mutate(
    taille_jaune = "Ensemble",
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_inter <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_inter),
    tot_dep_interm =  sum(dep_interm*poids_inter),
    tot_remb_aides = sum(remb_aides*poids_inter),
    tot_ms = sum(a6*poids_inter)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_b_inter <- data %>% 
  filter(annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_inter),
    tot_dep_interm =  sum(dep_interm*poids_inter),
    tot_remb_aides = sum(remb_aides*poids_inter),
    tot_ms = sum(a6*poids_inter)
  ) %>% 
  mutate(
    taille_jaune = "Ensemble",
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_new_sans_icarus <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new_sans_icarus),
    tot_dep_interm =  sum(dep_interm*poids_new_sans_icarus),
    tot_remb_aides = sum(remb_aides*poids_new_sans_icarus),
    tot_ms = sum(a6*poids_new_sans_icarus)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_b_new_sans_icarus <- data %>% 
  filter(annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new_sans_icarus),
    tot_dep_interm =  sum(dep_interm*poids_new_sans_icarus),
    tot_remb_aides = sum(remb_aides*poids_new_sans_icarus),
    tot_ms = sum(a6*poids_new_sans_icarus)
  ) %>% 
  mutate(
    taille_jaune = "Ensemble",
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_new <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new),
    tot_dep_interm =  sum(dep_interm*poids_new),
    tot_remb_aides = sum(remb_aides*poids_new),
    tot_ms = sum(a6*poids_new)
  ) %>% 
  mutate(
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 

tableau24_b_new <- data %>% 
  filter(annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new),
    tot_dep_interm =  sum(dep_interm*poids_new),
    tot_remb_aides = sum(remb_aides*poids_new),
    tot_ms = sum(a6*poids_new)
  ) %>% 
  mutate(
    taille_jaune = "Ensemble",
    tot_dep_brutes = tot_dep_directes + tot_dep_interm,
    tx_remb_aides = paste0(round(tot_remb_aides*100/tot_dep_brutes,0),"%"),
    tot_dep_nettes = tot_dep_brutes - tot_remb_aides,
    
    tx_dep_dir_ms = paste0(round(tot_dep_directes*100/tot_ms,1),"%"),
    tx_dep_interm_ms = paste0(round(tot_dep_interm*100/tot_ms,1),"%"),
    tx_remb_aides_ms = paste0(round(tot_remb_aides*100/tot_ms,1),"%"),
    tx_particip_ms = paste0(round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),"%"),
    
    across(c(tot_dep_directes,tot_dep_interm,tot_dep_brutes,tot_remb_aides,tot_dep_nettes),
           ~ round(./1e9, 1)
    )
  ) 
tableau24_old <- bind_rows(tableau24_old, tableau24_b_old)
tableau24_inter <- bind_rows(tableau24_inter, tableau24_b_inter)
tableau24_new_sans_icarus <- bind_rows(tableau24_new_sans_icarus, tableau24_b_new_sans_icarus)
tableau24_new <- bind_rows(tableau24_new, tableau24_b_new)

# 
# tableau24_old
# tableau24_inter
# tableau24_new
# tableau24_new_sans_icarus 
tab24_old <- tableau24_old |>
  gt() |> 
  tab_header(
    title = md("**Dépenses et remboursements – EFE 2024 par taille**"), 
    subtitle = "Ancienne ponderation"
  ) |>
  cols_label(
    tot_dep_directes = "Tot. Dép. Directes",
    tot_dep_interm = "Tot. Dép. Intermédiaires",
    tot_remb_aides = "Tot. Remb. Aides",
    tot_ms = "Tot. MS",
    tot_dep_brutes = "Tot. Dép. Brutes",
    tx_remb_aides = "Tx Remb. Aides",
    tot_dep_nettes = "Tot. Dép. Nettes" )|> 
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_column_labels(columns = everything())
  ) |>
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_body(columns = everything())
  ) |>
  cols_width(
    everything() ~ px(160)
  ) |>
  cols_width(
    tot_ms ~ px(220)   # 👈 colonne Masse salariale plus large
  ) |>
  tab_style(
    style = cell_fill(color = "#7fb7df"),
    locations = cells_body(rows = everything())
  ) |>
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything())
  ) |>
 tab_options(
  table.layout = "auto",
  table.width  = pct(100),
  data_row.padding = px(8)
)

tab24_old
Dépenses et remboursements – EFE 2024 par taille
Ancienne ponderation
taille_jaune Tot. Dép. Directes Tot. Dép. Intermédiaires Tot. Remb. Aides Tot. MS Tot. Dép. Brutes Tx Remb. Aides Tot. Dép. Nettes tx_dep_dir_ms tx_dep_interm_ms tx_remb_aides_ms tx_particip_ms
Moins de 50 salariés 3.1 4.0 0.5 266662597743 7.2 8% 6.6 1.2% 1.5% 0.2% 2.5%
De 50 à 249 salariés 2.8 2.6 0.3 143829673813 5.5 5% 5.2 2% 1.8% 0.2% 3.6%
De 250 à 999 salariés 3.1 2.4 0.1 129884852748 5.5 3% 5.4 2.4% 1.8% 0.1% 4.1%
1000 salariés ou plus 7.3 3.8 0.2 208934607722 11.1 2% 10.8 3.5% 1.8% 0.1% 5.2%
Ensemble 16.4 12.8 1.2 749311732026 29.2 4% 28.0 2.2% 1.7% 0.2% 3.7%
#########
tab24_inter <- tableau24_inter |>
  gt() |> 
  tab_header(
    title = md("**Dépenses et remboursements – EFE 2024 par taille**"), 
    subtitle = "Ponderation Intermediaire"
  ) |>
  cols_label(
    tot_dep_directes = "Tot. Dép. Directes",
    tot_dep_interm = "Tot. Dép. Intermédiaires",
    tot_remb_aides = "Tot. Remb. Aides",
    tot_ms = "Tot. MS",
    tot_dep_brutes = "Tot. Dép. Brutes",
    tx_remb_aides = "Tx Remb. Aides",
    tot_dep_nettes = "Tot. Dép. Nettes"
  ) |>
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_column_labels(columns = everything())
  ) |>
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_body(columns = everything())
  ) |>
  cols_width(
    everything() ~ px(120)
  ) |>
    cols_width(
    tot_ms ~ px(220)   # 👈 colonne Masse salariale plus large
  ) |>
  tab_style(
    style = cell_fill(color = "#328ccc"),
    locations = cells_body(rows = everything())
  ) |>
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything())
  ) |>
  tab_options(
  table.layout = "auto",
  table.width  = pct(100),
  data_row.padding = px(8)
)

tab24_inter
Dépenses et remboursements – EFE 2024 par taille
Ponderation Intermediaire
taille_jaune Tot. Dép. Directes Tot. Dép. Intermédiaires Tot. Remb. Aides Tot. MS Tot. Dép. Brutes Tx Remb. Aides Tot. Dép. Nettes tx_dep_dir_ms tx_dep_interm_ms tx_remb_aides_ms tx_particip_ms
Moins de 50 salariés 3.1 4.0 0.5 267186780999 7.1 7% 6.6 1.2% 1.5% 0.2% 2.5%
De 50 à 249 salariés 2.8 2.6 0.3 144276798120 5.4 5% 5.2 1.9% 1.8% 0.2% 3.6%
De 250 à 999 salariés 3.1 2.3 0.1 127917941767 5.4 3% 5.3 2.4% 1.8% 0.1% 4.1%
1000 salariés ou plus 7.5 3.8 0.2 212902135743 11.4 2% 11.1 3.5% 1.8% 0.1% 5.2%
Ensemble 16.5 12.8 1.2 752283656629 29.4 4% 28.2 2.2% 1.7% 0.2% 3.7%
#########


tab24_new_sans_icarus <- tableau24_new_sans_icarus |>
  gt() |> 
  tab_header(
    title = md("**Dépenses et remboursements – EFE 2024 par taille**"), 
    subtitle = "Ponderation nouvelle sans Icarus"
  ) |>
  cols_label(
    tot_dep_directes = "Tot. Dép. Directes",
    tot_dep_interm = "Tot. Dép. Intermédiaires",
    tot_remb_aides = "Tot. Remb. Aides",
    tot_ms = "Tot. MS",
    tot_dep_brutes = "Tot. Dép. Brutes",
    tx_remb_aides = "Tx Remb. Aides",
    tot_dep_nettes = "Tot. Dép. Nettes"
  ) |>
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_column_labels(columns = everything())
  ) |>
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_body(columns = everything())
  ) |>
  cols_width(
    everything() ~ px(120)
  ) |>
    cols_width(
    tot_ms ~ px(220)   # 👈 colonne Masse salariale plus large
  ) |>
  tab_style(
    style = cell_fill(color = "#1f6fa3"),
    locations = cells_body(rows = everything())
  ) |>
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything())
  ) |>
 tab_options(
  table.layout = "auto",
  table.width  = pct(100),
  data_row.padding = px(8)
)

tab24_new_sans_icarus
Dépenses et remboursements – EFE 2024 par taille
Ponderation nouvelle sans Icarus
taille_jaune Tot. Dép. Directes Tot. Dép. Intermédiaires Tot. Remb. Aides Tot. MS Tot. Dép. Brutes Tx Remb. Aides Tot. Dép. Nettes tx_dep_dir_ms tx_dep_interm_ms tx_remb_aides_ms tx_particip_ms
Moins de 50 salariés 3.1 4.1 0.5 267412335302 7.1 7% 6.6 1.1% 1.5% 0.2% 2.5%
De 50 à 249 salariés 2.8 2.6 0.3 143537163017 5.4 5% 5.1 1.9% 1.8% 0.2% 3.5%
De 250 à 999 salariés 3.1 2.3 0.2 128618759754 5.4 3% 5.3 2.4% 1.8% 0.1% 4.1%
1000 salariés ou plus 7.4 3.8 0.2 210651259783 11.2 2% 11.0 3.5% 1.8% 0.1% 5.2%
Ensemble 16.3 12.8 1.2 750219517855 29.1 4% 28.0 2.2% 1.7% 0.2% 3.7%
tab24_new_avec_icarus <- tableau24_new|>
  gt() |> 
  tab_header(
    title = md("**Dépenses et remboursements – EFE 2024 par taille**"), 
    subtitle = "Ponderation nouvelle avec Icarus"
  ) |>
  cols_label(
    tot_dep_directes = "Tot. Dép. Directes",
    tot_dep_interm = "Tot. Dép. Intermédiaires",
    tot_remb_aides = "Tot. Remb. Aides",
    tot_ms = "Tot. MS",
    tot_dep_brutes = "Tot. Dép. Brutes",
    tx_remb_aides = "Tx Remb. Aides",
    tot_dep_nettes = "Tot. Dép. Nettes"
  ) |>
   fmt_number(
    columns = c(tot_ms),
    decimals = 0,
    sep_mark = " ",
    dec_mark = ","
  ) |> 
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_column_labels(columns = everything())
  ) |>
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_body(columns = everything())
  ) |>
  cols_width(
    everything() ~ px(120)
  ) |>
    cols_width(
    tot_ms ~ px(220)   # 👈 colonne Masse salariale plus large
  ) |>
  tab_style(
    style = cell_fill(color = "#0b4f6c"),
    locations = cells_body(rows = everything())
  ) |>
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything())
  ) |>
tab_options(
  table.layout = "auto",
  table.width  = pct(100),
  data_row.padding = px(8)
)


tab24_new_avec_icarus
Dépenses et remboursements – EFE 2024 par taille
Ponderation nouvelle avec Icarus
taille_jaune Tot. Dép. Directes Tot. Dép. Intermédiaires Tot. Remb. Aides Tot. MS Tot. Dép. Brutes Tx Remb. Aides Tot. Dép. Nettes tx_dep_dir_ms tx_dep_interm_ms tx_remb_aides_ms tx_particip_ms
Moins de 50 salariés 3.0 4.1 0.5 268 236 346 621 7.1 7% 6.6 1.1% 1.5% 0.2% 2.5%
De 50 à 249 salariés 2.7 2.6 0.3 142 284 011 696 5.3 5% 5.1 1.9% 1.8% 0.2% 3.6%
De 250 à 999 salariés 3.1 2.4 0.1 130 111 311 258 5.5 3% 5.3 2.4% 1.8% 0.1% 4.1%
1000 salariés ou plus 7.1 3.7 0.2 207 267 373 121 10.8 2% 10.6 3.4% 1.8% 0.1% 5.1%
Ensemble 16.0 12.7 1.1 747 899 042 696 28.7 4% 27.6 2.1% 1.7% 0.2% 3.7%

3.1.3 Tableau 3 : Taux d’effort

tableau3_old <- data %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_old),
    tot_dep_interm =  sum(dep_interm*poids_old),
    tot_remb_aides = sum(remb_aides*poids_old),
    tot_ms = sum(a6*poids_old)
  ) %>% 
  mutate(
    dep_dir_ms = tot_dep_directes*100/tot_ms,
    dep_interm_ms = tot_dep_interm*100/tot_ms,
    remb_aides_ms = tot_remb_aides*100/tot_ms,
    tx_particip = (tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,
  ) %>% 
  select( dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip)

tableau3_inter<- data %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_inter),
    tot_dep_interm =  sum(dep_interm*poids_inter),
    tot_remb_aides = sum(remb_aides*poids_inter),
    tot_ms = sum(a6*poids_inter)
  ) %>% 
  mutate(
    dep_dir_ms = tot_dep_directes*100/tot_ms,
    dep_interm_ms = tot_dep_interm*100/tot_ms,
    remb_aides_ms = tot_remb_aides*100/tot_ms,
    tx_particip = (tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,
  ) %>% 
  select( dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip)


tableau3_new <- data %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new),
    tot_dep_interm =  sum(dep_interm*poids_new),
    tot_remb_aides = sum(remb_aides*poids_new),
    tot_ms = sum(a6*poids_new)
  ) %>% 
  mutate(
    dep_dir_ms = tot_dep_directes*100/tot_ms,
    dep_interm_ms = tot_dep_interm*100/tot_ms,
    remb_aides_ms = tot_remb_aides*100/tot_ms,
    tx_particip = (tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,
  ) %>% 
  select( dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip)

tableau3_new_sans_icarus <- data %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new_sans_icarus),
    tot_dep_interm =  sum(dep_interm*poids_new_sans_icarus),
    tot_remb_aides = sum(remb_aides*poids_new_sans_icarus),
    tot_ms = sum(a6*poids_new_sans_icarus)
  ) %>% 
  mutate(
    dep_dir_ms = tot_dep_directes*100/tot_ms,
    dep_interm_ms = tot_dep_interm*100/tot_ms,
    remb_aides_ms = tot_remb_aides*100/tot_ms,
    tx_particip = (tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,
  ) %>% 
  select( dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip)

# tableau3_old
# tableau3_inter
# tableau3_new
# tableau3_new_sans_icarus

 tableau3 <- rbind(tableau3_old |> mutate(ponderation="Ancienne"),
tableau3_inter |> mutate(ponderation="Intermediaire"),
tableau3_new_sans_icarus|> mutate(ponderation="Nouvelle sans Icarus"),
tableau3_new |> mutate(ponderation="Nouvelle") 
) |> 
   select(ponderation, everything())

#tableau3
gt_table3 <- tableau3 |>
  gt(rowname_col = "ponderation") |>

  # Titre et sous-titre
  tab_header(
    title = md("**Dépenses et taux de participation en fonction de la masse salariale – EFE 2024**"),
    subtitle = md("Comparaison pondérations anciennes, intermédiaires et nouvelles")
  ) |>
  # Labels des colonnes en toutes lettres
  cols_label(
    dep_dir_ms = "Dép. Directes",
    dep_interm_ms = "Dép. Intermédiaires",
    remb_aides_ms = "Remb. Aides",
    tx_particip = "Taux de participation"
  ) |>

  # Centrage de toutes les colonnes
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_column_labels(columns = everything())
  ) |>
  tab_style(
    style = cell_text(align = "center"),
    locations = cells_body(columns = everything())
  ) |>

  # Largeur identique pour toutes les colonnes
  cols_width(
    everything() ~ px(120)
  ) |>

  # Couleurs alternées pour les lignes
  tab_style(
    style = cell_fill(color = "#7fb7df"),
    locations = cells_body(rows = ponderation == "Ancienne")
  ) |>
  tab_style(
    style = cell_fill(color = "#328ccc"),
    locations = cells_body(rows = ponderation == "Intermediaire")
  ) |>
  tab_style(
    style = cell_fill(color = "#1f6fa3"),
    locations = cells_body(rows = ponderation == "Nouvelle sans Icarus")
  ) |>
  tab_style(
    style = cell_fill(color = "#0b4f6c"),
    locations = cells_body(rows = ponderation == "Nouvelle")
  ) |>

  # Texte en blanc sur les couleurs
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything())
  ) |>

  tab_options(
    data_row.padding = px(8)
  )

gt_table3
Dépenses et taux de participation en fonction de la masse salariale – EFE 2024
Comparaison pondérations anciennes, intermédiaires et nouvelles
Dép. Directes Dép. Intermédiaires Remb. Aides Taux de participation
Ancienne 2.185318 1.708186 0.1598970 3.733607
Intermediaire 2.196942 1.707132 0.1578381 3.746237
Nouvelle sans Icarus 2.177237 1.706027 0.1541960 3.729067
Nouvelle 2.135704 1.704601 0.1512951 3.689010

3.1.4 Tableau 5 : Taux d’effort par secteur en 2024

tableau5_old <- data %>% 
  filter(annee == "2024") %>% 
  group_by(secteur_jaune_lib) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_old),
    tot_dep_interm =  sum(dep_interm*poids_old),
    tot_remb_aides = sum(remb_aides*poids_old),
    tot_ms = sum(a6*poids_old)
  ) %>% 
  mutate(
    dep_dir_ms = round(tot_dep_directes*100/tot_ms,1),
    dep_interm_ms = round(tot_dep_interm*100/tot_ms,1),
    remb_aides_ms = round(tot_remb_aides*100/tot_ms,1),
    tx_particip = round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),
  ) %>% 
  select(secteur_jaune_lib, dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip)

tableau5_b_old <- data %>% 
  filter(tertiaire == 1 & annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_old),
    tot_dep_interm =  sum(dep_interm*poids_old),
    tot_remb_aides = sum(remb_aides*poids_old),
    tot_ms = sum(a6*poids_old)
  ) %>% 
  mutate(
    secteur_jaune_lib = "Tertiaire",
    dep_dir_ms = round(tot_dep_directes*100/tot_ms,1),
    dep_interm_ms = round(tot_dep_interm*100/tot_ms,1),
    remb_aides_ms = round(tot_remb_aides*100/tot_ms,1),
    tx_particip = round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),
  ) %>% 
  select(secteur_jaune_lib, dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip) 

tableau5_old <- bind_rows(tableau5_old, tableau5_b_old) %>% 
  mutate(
    secteur_jaune_lib = factor(secteur_jaune_lib, levels = c(
      "Agriculture",
      "Industrie",
      "Construction",
      "Tertiaire",
      "Commerce et réparation d'automobiles",
      "Transports et entreposage",
      "Hébergement et restauration",
      "Information et communication",
      "Activités financières et d'assurance",
      "Activités immobilières et scientifiques",
      "Services administratifs et de soutien",
      "Arts et spectacles",
      "Enseignement et santé")
    )
  ) %>% 
  arrange(secteur_jaune_lib)


tableau5_inter <- data %>% 
  filter(annee == "2024") %>% 
  group_by(secteur_jaune_lib) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_inter),
    tot_dep_interm =  sum(dep_interm*poids_inter),
    tot_remb_aides = sum(remb_aides*poids_inter),
    tot_ms = sum(a6*poids_inter)
  ) %>% 
  mutate(
    dep_dir_ms = round(tot_dep_directes*100/tot_ms,1),
    dep_interm_ms = round(tot_dep_interm*100/tot_ms,1),
    remb_aides_ms = round(tot_remb_aides*100/tot_ms,1),
    tx_particip = round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),
  ) %>% 
  select(secteur_jaune_lib, dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip)

tableau5_b_inter <- data %>% 
  filter(tertiaire == 1 & annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_inter),
    tot_dep_interm =  sum(dep_interm*poids_inter),
    tot_remb_aides = sum(remb_aides*poids_inter),
    tot_ms = sum(a6*poids_inter)
  ) %>% 
  mutate(
    secteur_jaune_lib = "Tertiaire",
    dep_dir_ms = round(tot_dep_directes*100/tot_ms,1),
    dep_interm_ms = round(tot_dep_interm*100/tot_ms,1),
    remb_aides_ms = round(tot_remb_aides*100/tot_ms,1),
    tx_particip = round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),
  ) %>% 
  select(secteur_jaune_lib, dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip) 

tableau5_inter <- bind_rows(tableau5_inter, tableau5_b_inter) %>% 
  mutate(
    secteur_jaune_lib = factor(secteur_jaune_lib, levels = c(
      "Agriculture",
      "Industrie",
      "Construction",
      "Tertiaire",
      "Commerce et réparation d'automobiles",
      "Transports et entreposage",
      "Hébergement et restauration",
      "Information et communication",
      "Activités financières et d'assurance",
      "Activités immobilières et scientifiques",
      "Services administratifs et de soutien",
      "Arts et spectacles",
      "Enseignement et santé")
    )
  ) %>% 
  arrange(secteur_jaune_lib)


tableau5_new <- data %>% 
  filter(annee == "2024") %>% 
  group_by(secteur_jaune_lib) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new),
    tot_dep_interm =  sum(dep_interm*poids_new),
    tot_remb_aides = sum(remb_aides*poids_new),
    tot_ms = sum(a6*poids_new)
  ) %>% 
  mutate(
    dep_dir_ms = round(tot_dep_directes*100/tot_ms,1),
    dep_interm_ms = round(tot_dep_interm*100/tot_ms,1),
    remb_aides_ms = round(tot_remb_aides*100/tot_ms,1),
    tx_particip = round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),
  ) %>% 
  select(secteur_jaune_lib, dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip)

tableau5_b_new <- data %>% 
  filter(tertiaire == 1 & annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new),
    tot_dep_interm =  sum(dep_interm*poids_new),
    tot_remb_aides = sum(remb_aides*poids_new),
    tot_ms = sum(a6*poids_new)
  ) %>% 
  mutate(
    secteur_jaune_lib = "Tertiaire",
    dep_dir_ms = round(tot_dep_directes*100/tot_ms,1),
    dep_interm_ms = round(tot_dep_interm*100/tot_ms,1),
    remb_aides_ms = round(tot_remb_aides*100/tot_ms,1),
    tx_particip = round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),
  ) %>% 
  select(secteur_jaune_lib, dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip) 

tableau5_new <- bind_rows(tableau5_new, tableau5_b_new) %>% 
  mutate(
    secteur_jaune_lib = factor(secteur_jaune_lib, levels = c(
      "Agriculture",
      "Industrie",
      "Construction",
      "Tertiaire",
      "Commerce et réparation d'automobiles",
      "Transports et entreposage",
      "Hébergement et restauration",
      "Information et communication",
      "Activités financières et d'assurance",
      "Activités immobilières et scientifiques",
      "Services administratifs et de soutien",
      "Arts et spectacles",
      "Enseignement et santé")
    )
  ) %>% 
  arrange(secteur_jaune_lib)




tableau5_new_sans_icarus <- data %>% 
  filter(annee == "2024") %>% 
  group_by(secteur_jaune_lib) %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new_sans_icarus),
    tot_dep_interm =  sum(dep_interm*poids_new_sans_icarus),
    tot_remb_aides = sum(remb_aides*poids_new_sans_icarus),
    tot_ms = sum(a6*poids_new_sans_icarus)
  ) %>% 
  mutate(
    dep_dir_ms = round(tot_dep_directes*100/tot_ms,1),
    dep_interm_ms = round(tot_dep_interm*100/tot_ms,1),
    remb_aides_ms = round(tot_remb_aides*100/tot_ms,1),
    tx_particip = round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),
  ) %>% 
  select(secteur_jaune_lib, dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip)

tableau5_b_new_sans_icarus <- data %>% 
  filter(tertiaire == 1 & annee == "2024") %>% 
  summarise(
    tot_dep_directes = sum(dep_directes*poids_new_sans_icarus),
    tot_dep_interm =  sum(dep_interm*poids_new_sans_icarus),
    tot_remb_aides = sum(remb_aides*poids_new_sans_icarus),
    tot_ms = sum(a6*poids_new_sans_icarus)
  ) %>% 
  mutate(
    secteur_jaune_lib = "Tertiaire",
    dep_dir_ms = round(tot_dep_directes*100/tot_ms,1),
    dep_interm_ms = round(tot_dep_interm*100/tot_ms,1),
    remb_aides_ms = round(tot_remb_aides*100/tot_ms,1),
    tx_particip = round((tot_dep_directes+tot_dep_interm-tot_remb_aides)*100/tot_ms,1),
  ) %>% 
  select(secteur_jaune_lib, dep_dir_ms, dep_interm_ms, remb_aides_ms,tx_particip) 

tableau5_new_sans_icarus <- bind_rows(tableau5_new_sans_icarus, tableau5_b_new_sans_icarus) %>% 
  mutate(
    secteur_jaune_lib = factor(secteur_jaune_lib, levels = c(
      "Agriculture",
      "Industrie",
      "Construction",
      "Tertiaire",
      "Commerce et réparation d'automobiles",
      "Transports et entreposage",
      "Hébergement et restauration",
      "Information et communication",
      "Activités financières et d'assurance",
      "Activités immobilières et scientifiques",
      "Services administratifs et de soutien",
      "Arts et spectacles",
      "Enseignement et santé")
    )
  ) %>% 
  arrange(secteur_jaune_lib)


tableau5 <- tableau5_old |>
  rename_with(~ paste0(.x, "_old"), -secteur_jaune_lib) |>
  left_join(
    tableau5_inter |>
      rename_with(~ paste0(.x, "_inter"), -secteur_jaune_lib),
    by = "secteur_jaune_lib"
  ) |>
  left_join(
    tableau5_new_sans_icarus |>
      rename_with(~ paste0(.x, "_new_sans_icarus"), -secteur_jaune_lib),
    by = "secteur_jaune_lib"
  ) |>
  left_join(
    tableau5_new |>
      rename_with(~ paste0(.x, "_new"), -secteur_jaune_lib),
    by = "secteur_jaune_lib"
  )
gt_table_5 <- tableau5 |>
  gt(rowname_col = "secteur_jaune_lib") |>

  tab_header(
    title = md("**Dépenses et taux de participation par secteur – EFE 2024**"),
    subtitle = md("Comparaison pondérations anciennes, intermédiaires et nouvelles")
  ) |>

  cols_label(
    dep_dir_ms_old = "Dép. Directes",
    dep_interm_ms_old = "Dép. Intermédiaires",
    remb_aides_ms_old = "Remb. Aides",
    tx_particip_old = "Taux de participation",

    dep_dir_ms_inter = "Dép. Directes",
    dep_interm_ms_inter = "Dép. Intermédiaires",
    remb_aides_ms_inter = "Remb. Aides",
    tx_particip_inter = "Taux de participation",

    dep_dir_ms_new_sans_icarus = "Dép. Directes",
    dep_interm_ms_new_sans_icarus = "Dép. Intermédiaires",
    remb_aides_ms_new_sans_icarus = "Remb. Aides",
    tx_particip_new_sans_icarus = "Taux de participation",

    dep_dir_ms_new = "Dép. Directes",
    dep_interm_ms_new = "Dép. Intermédiaires",
    remb_aides_ms_new = "Remb. Aides",
    tx_particip_new = "Taux de participation"
  ) |>

  # Spanners
  tab_spanner("Ancienne", ends_with("_old")) |>
  tab_spanner("Intermédiaire", ends_with("_inter")) |>
  tab_spanner("Nouvelle sans Icarus", ends_with("_new_sans_icarus")) |>
  tab_spanner("Nouvelle", ends_with("_new")) |>

  # Centrage
  tab_style(
    style = cell_text(align = "center"),
    locations = list(
      cells_column_labels(everything()),
      cells_body(everything())
    )
  ) |>

  cols_width(everything() ~ px(120)) |>

  # === COULEURS PAR PONDÉRATION ===
  tab_style(
    style = cell_fill(color = "#7fb7df"),
    locations = cells_body(columns = ends_with("_old"))
  ) |>
  tab_style(
    style = cell_fill(color = "#328ccc"),
    locations = cells_body(columns = ends_with("_inter"))
  ) |>
  tab_style(
    style = cell_fill(color = "#1f6fa3"),
    locations = cells_body(columns = ends_with("_new_sans_icarus"))
  ) |>
  tab_style(
    style = cell_fill(color = "#0b4f6c"),
    locations = cells_body(columns = ends_with("_new"))
  ) |>

  # Texte blanc et gras sur fond coloré
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything())
  ) |>

  tab_options(
    data_row.padding = px(8)
  )

gt_table_5
Dépenses et taux de participation par secteur – EFE 2024
Comparaison pondérations anciennes, intermédiaires et nouvelles
Ancienne
Intermédiaire
Nouvelle sans Icarus
Nouvelle
Dép. Directes Dép. Intermédiaires Remb. Aides Taux de participation Dép. Directes Dép. Intermédiaires Remb. Aides Taux de participation Dép. Directes Dép. Intermédiaires Remb. Aides Taux de participation Dép. Directes Dép. Intermédiaires Remb. Aides Taux de participation
Agriculture 0.8 1.2 0.1 1.8 0.8 1.2 0.1 1.8 0.8 1.2 0.1 1.8 0.8 1.2 0.1 1.8
Industrie 2.9 1.8 0.1 4.6 2.9 1.8 0.1 4.6 3.0 1.8 0.1 4.6 2.9 1.8 0.1 4.6
Construction 1.9 1.7 0.2 3.3 1.8 1.7 0.2 3.3 1.8 1.7 0.2 3.2 1.7 1.6 0.2 3.1
Tertiaire 2.1 1.7 0.2 3.6 2.1 1.7 0.2 3.6 2.0 1.7 0.2 3.6 2.0 1.7 0.2 3.5
Commerce et réparation d'automobiles 1.4 1.7 0.1 2.9 1.3 1.7 0.1 2.9 1.3 1.7 0.1 2.8 1.2 1.7 0.1 2.8
Transports et entreposage 3.0 1.9 0.1 4.8 3.3 1.9 0.1 5.1 3.4 1.9 0.1 5.2 3.0 1.9 0.1 4.8
Hébergement et restauration 0.7 1.5 0.1 2.2 0.7 1.5 0.1 2.2 0.6 1.5 0.0 2.1 0.6 1.6 0.0 2.1
Information et communication 2.0 1.7 0.0 3.6 1.9 1.7 0.0 3.6 1.9 1.7 0.0 3.6 1.8 1.7 0.0 3.5
Activités financières et d'assurance 3.3 1.7 0.1 4.9 3.3 1.7 0.1 4.9 3.2 1.7 0.1 4.8 3.3 1.7 0.1 4.9
Activités immobilières et scientifiques 2.1 1.6 0.1 3.6 2.0 1.6 0.1 3.6 2.0 1.6 0.1 3.5 2.0 1.6 0.1 3.5
Services administratifs et de soutien 1.7 1.8 0.3 3.3 1.7 1.8 0.3 3.2 1.7 1.8 0.3 3.2 1.7 1.8 0.3 3.3
Arts et spectacles 2.2 1.7 0.3 3.5 2.2 1.6 0.3 3.5 2.1 1.6 0.3 3.4 2.1 1.7 0.3 3.4
Enseignement et santé 2.7 1.7 0.4 4.0 2.7 1.7 0.5 4.0 2.8 1.7 0.5 4.0 2.8 1.7 0.4 4.1

3.2 Contribution

3.2.1 Tableau Contribution

# évolution par contribution
supp_old <- data %>% 
  summarise(
    tot_b5am = sum(b5am*poids_old)/1000000000,
    tot_b5ad =  sum(b5ad*poids_old)/1000000000,
    tot_b5amcdd = sum(b5amcdd*poids_old)/1000000000,
    tot_b5abm = sum(b5abm*poids_old)/1000000000,
    tot_b5acm = sum(b5acm*poids_old)/1000000000
  )
supp_inter <- data %>% 
  summarise(
    tot_b5am = sum(b5am*poids_inter)/1000000000,
    tot_b5ad =  sum(b5ad*poids_inter)/1000000000,
    tot_b5amcdd = sum(b5amcdd*poids_inter)/1000000000,
    tot_b5abm = sum(b5abm*poids_inter)/1000000000,
    tot_b5acm = sum(b5acm*poids_inter)/1000000000
  )
supp_new_sans_icarus <- data %>% 
  summarise(
    tot_b5am = sum(b5am*poids_new_sans_icarus)/1000000000,
    tot_b5ad =  sum(b5ad*poids_new_sans_icarus)/1000000000,
    tot_b5amcdd = sum(b5amcdd*poids_new_sans_icarus)/1000000000,
    tot_b5abm = sum(b5abm*poids_new_sans_icarus)/1000000000,
    tot_b5acm = sum(b5acm*poids_new_sans_icarus)/1000000000
  )
    
    
    
supp_new <- data %>% 
  summarise(
    tot_b5am = sum(b5am*poids_new)/1000000000,
    tot_b5ad =  sum(b5ad*poids_new)/1000000000,
    tot_b5amcdd = sum(b5amcdd*poids_new)/1000000000,
    tot_b5abm = sum(b5abm*poids_new)/1000000000,
    tot_b5acm = sum(b5acm*poids_new)/1000000000
  )


contrib <- rbind(
  supp_old |> mutate(ponderation="Ancienne"),
  supp_inter|> mutate(ponderation="Intermediare"),
  supp_new_sans_icarus|> mutate(ponderation="Nouvelle sans Icarus"),
  supp_new|> mutate(ponderation="Nouvelle avec Icarus")) |> select(ponderation, everything()) 
gt_table_contrib <- contrib |>
  gt(rowname_col = "ponderation") |>

  # Titre
  tab_header(
    title = md("**Contribution selon la pondération – EFE 2024**"),
    subtitle = md("Comparaison pondérations anciennes et nouvelles")
  ) |>

  # Labels des colonnes
  cols_label(
    tot_b5am    = "Contribution à la formation professionnelle",
    tot_b5ad    = "Part principale de la taxe d’apprentissage",
    tot_b5amcdd = "Contribution CPF-CDD",
    tot_b5abm   = "Contribution conventionnelle",
    tot_b5acm   = "Versements volontaires"
  ) |>

  # Format numérique
  fmt_number(
    columns = everything(),
    decimals = 2
  ) |>

  # Centrage
  tab_style(
    style = cell_text(align = "center"),
    locations = list(
      cells_column_labels(everything()),
      cells_body(everything())
    )
  ) |>

  # Largeur des colonnes
  cols_width(
    everything() ~ px(140)
  ) |>

  # === COULEURS PAR PONDÉRATION (LIGNES) ===
  tab_style(
    style = cell_fill(color = "#7fb7df"),
    locations = cells_body(rows = ponderation == "Ancienne")
  ) |>
  tab_style(
    style = cell_fill(color = "#328ccc"),
    locations = cells_body(rows = ponderation == "Intermediare")
  ) |>
  tab_style(
    style = cell_fill(color = "#1f6fa3"),
    locations = cells_body(rows = ponderation == "Nouvelle sans Icarus")
  ) |>
  tab_style(
    style = cell_fill(color = "#0b4f6c"),
    locations = cells_body(rows = ponderation == "Nouvelle avec Icarus")
  ) |>

  # Texte blanc et gras
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything())
  ) |>

  tab_options(
    data_row.padding = px(8)
  )

gt_table_contrib
Contribution selon la pondération – EFE 2024
Comparaison pondérations anciennes et nouvelles
Contribution à la formation professionnelle Part principale de la taxe d’apprentissage Contribution CPF-CDD Contribution conventionnelle Versements volontaires
Ancienne 6.68 4.67 0.30 0.85 0.31
Intermediare 6.70 4.68 0.30 0.85 0.31
Nouvelle sans Icarus 6.69 4.68 0.30 0.83 0.30
Nouvelle avec Icarus 6.66 4.67 0.29 0.81 0.31

3.2.2 Tableau Contribution par OPCO

# évolution conventionnelle par opco
conv_old <- data %>% 
  group_by( opco2024) %>% 
  summarise(
    tot_b5abm = sum(b5abm*poids_old)/1000000000,
  )
conv_inter <- data %>% 
  group_by( opco2024) %>% 
  summarise(
    tot_b5abm = sum(b5abm*poids_inter)/1000000000,
  )

conv_new_sans_icarus <- data %>% 
  group_by( opco2024) %>% 
  summarise(
    tot_b5abm = sum(b5abm*poids_new_sans_icarus)/1000000000,
  )

conv_new <- data %>% 
  group_by( opco2024) %>% 
  summarise(
    tot_b5abm = sum(b5abm*poids_new)/1000000000,
  )


opco <- conv_old |>
  left_join(
    conv_inter,
    by = "opco2024",
    suffix = c("_old", "_inter")
  ) |>
  left_join(
    conv_new_sans_icarus |>
      rename_with(~ paste0(.x, "_new_sans_icarus"), -opco2024),
    by = "opco2024"
  ) |>
  left_join(
    conv_new |>
      rename_with(~ paste0(.x, "_new"), -opco2024),
    by = "opco2024"
  )
gt_table_opco <- opco |>
  gt(rowname_col = "opco2024") |>

  # Titre
  tab_header(
    title = md("**Répartition Contribution Conventionnelle par OPCO – EFE 2024**"),
    subtitle = md("Comparaison pondérations anciennes, intermédiaires et nouvelles")
  ) |>

  # Labels des colonnes
  cols_label(
    tot_b5abm_old = "Ancienne",
    tot_b5abm_inter = "Intermédiaire",
    tot_b5abm_new_sans_icarus = "Nouvelle sans Icarus",
    tot_b5abm_new = "Nouvelle"
  ) |>

  # Format numérique
  fmt_number(
    columns = everything(),
    decimals = 3
  ) |>

  # Centrage
  tab_style(
    style = cell_text(align = "center"),
    locations = list(
      cells_column_labels(everything()),
      cells_body(everything())
    )
  ) |>

  # Largeur
  cols_width(
    everything() ~ px(140)
  ) |>

  # === COULEURS PAR PONDÉRATION (COLONNES) ===
  tab_style(
    style = cell_fill(color = "#7fb7df"),
    locations = cells_body(columns = tot_b5abm_old)
  ) |>
  tab_style(
    style = cell_fill(color = "#328ccc"),
    locations = cells_body(columns = tot_b5abm_inter)
  ) |>
  tab_style(
    style = cell_fill(color = "#1f6fa3"),
    locations = cells_body(columns = tot_b5abm_new_sans_icarus)
  ) |>
  tab_style(
    style = cell_fill(color = "#0b4f6c"),
    locations = cells_body(columns = tot_b5abm_new)
  ) |>

  # Texte blanc et gras
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything())
  ) |>

  tab_options(
    data_row.padding = px(8)
  )

gt_table_opco
Répartition Contribution Conventionnelle par OPCO – EFE 2024
Comparaison pondérations anciennes, intermédiaires et nouvelles
Ancienne Intermédiaire Nouvelle sans Icarus Nouvelle
AFDAS 0.039 0.040 0.037 0.032
AKTO 0.137 0.136 0.131 0.133
ATLAS 0.053 0.054 0.053 0.057
Constructys 0.047 0.048 0.043 0.038
L'Opcommerce 0.013 0.013 0.012 0.013
NA 0.001 0.001 0.001 0.001
OCAPIAT 0.012 0.012 0.012 0.011
OPCO EP 0.089 0.091 0.090 0.081
OPCO2i 0.024 0.024 0.025 0.025
OpcoCohesion 0.148 0.142 0.140 0.148
OpcoMobilites 0.176 0.174 0.171 0.168
OpcoSante 0.108 0.112 0.111 0.102

4- Taux accès

4.1 Taux accès et heure pas formé

# Tableau 1: série taux d'accès et heures/salarié --------------

tableau1_old <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_old), 
    nb_salaries = sum(a2tot*poids_old),
    nb_heures = sum(c3tot*poids_old)
  ) %>% 
  mutate(
    tx_acces = round(nb_formes*100/nb_salaries,1),
    heures_par_forme = round(nb_heures/nb_formes,1)
  ) %>% 
  select(-starts_with("nb"))

tableau1_inter <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_inter), 
    nb_salaries = sum(a2tot*poids_inter),
    nb_heures = sum(c3tot*poids_inter)
  ) %>% 
  mutate(
    tx_acces = round(nb_formes*100/nb_salaries,1),
    heures_par_forme = round(nb_heures/nb_formes,1)
  ) %>% 
  select(-starts_with("nb"))

tableau1_new_sans_icarus <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new_sans_icarus), 
    nb_salaries = sum(a2tot*poids_new_sans_icarus),
    nb_heures = sum(c3tot*poids_new_sans_icarus)
  ) %>% 
  mutate(
    tx_acces = round(nb_formes*100/nb_salaries,1),
    heures_par_forme = round(nb_heures/nb_formes,1)
  ) %>% 
  select(-starts_with("nb"))



tableau1_new <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new), 
    nb_salaries = sum(a2tot*poids_new),
    nb_heures = sum(c3tot*poids_new)
  ) %>% 
  mutate(
    tx_acces = round(nb_formes*100/nb_salaries,1),
    heures_par_forme = round(nb_heures/nb_formes,1)
  ) %>% 
  select(-starts_with("nb"))


# tableau1_old
# tableau1_new
# tableau1_inter
# tableau1_new_sans_icarus



tx_acces_h_form <- rbind(
  tableau1_old |> mutate(ponderation="Ancienne"),
  tableau1_inter|> mutate(ponderation="Intermediare"),
  tableau1_new_sans_icarus|> mutate(ponderation="Nouvelle sans Icarus"),
  tableau1_new|> mutate(ponderation="Nouvelle avec Icarus")) |> select(ponderation, everything()) 
gt_table_tx <- tx_acces_h_form |>
  gt(rowname_col = "ponderation") |>

  tab_header(
    title = md("**Taux d’accès et durée de formation selon la pondération – EFE 2024**"),
    subtitle = md("Comparaison pondérations anciennes et nouvelles")
  ) |>

  cols_label(
    tx_acces = "Taux d’accès (%)",
    heures_par_forme = "Heures par formation"
  ) |>

  fmt_number(
    columns = c(tx_acces, heures_par_forme),
    decimals = 1
  ) |>

  # Centrage
  tab_style(
    style = cell_text(align = "center"),
    locations = list(
      cells_column_labels(everything()),
      cells_body(everything())
    )
  ) |>

  cols_width(
    everything() ~ px(160)
  ) |>

  # === COULEURS PAR PONDÉRATION (LIGNES) ===
  tab_style(
    style = cell_fill(color = "#7fb7df"),
    locations = cells_body(rows = ponderation == "Ancienne")
  ) |>
  tab_style(
    style = cell_fill(color = "#328ccc"),
    locations = cells_body(rows = ponderation == "Intermediare")
  ) |>
  tab_style(
    style = cell_fill(color = "#1f6fa3"),
    locations = cells_body(rows = ponderation == "Nouvelle sans Icarus")
  ) |>
  tab_style(
    style = cell_fill(color = "#0b4f6c"),
    locations = cells_body(rows = ponderation == "Nouvelle avec Icarus")
  ) |>

  # Texte blanc et gras
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything())
  ) |>

  tab_options(
    data_row.padding = px(8)
  )

gt_table_tx
Taux d’accès et durée de formation selon la pondération – EFE 2024
Comparaison pondérations anciennes et nouvelles
Taux d’accès (%) Heures par formation
Ancienne 43.7 31.6
Intermediare 43.8 31.3
Nouvelle sans Icarus 43.5 31.2
Nouvelle avec Icarus 43.2 31.2

4.2 Taux d’accès par taille en 2024

# Tableau 2: taux d'accès par taille en 2024 ----------------------------------------

tableau2_a_old <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_old), 
    nb_salaries = sum(a2tot*poids_old),
    nb_heures = sum(c3tot*poids_old)
  ) 

tableau2_a_inter <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_inter), 
    nb_salaries = sum(a2tot*poids_inter),
    nb_heures = sum(c3tot*poids_inter)
  ) 

tableau2_a_new_sans_icarus <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new_sans_icarus), 
    nb_salaries = sum(a2tot*poids_new_sans_icarus),
    nb_heures = sum(c3tot*poids_new_sans_icarus)
  ) 

tableau2_a_new <- data %>% 
  group_by(taille_jaune) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new), 
    nb_salaries = sum(a2tot*poids_new),
    nb_heures = sum(c3tot*poids_new)
  ) 





tableau2_b_old <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_old), 
    nb_salaries = sum(a2tot*poids_old),
    nb_heures = sum(c3tot*poids_old)
  ) %>% 
  mutate(taille_jaune = "Ensemble")


tableau2_b_inter <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_inter), 
    nb_salaries = sum(a2tot*poids_inter),
    nb_heures = sum(c3tot*poids_inter)
  ) %>% 
  mutate(taille_jaune = "Ensemble")

tableau2_b_new_sans_icarus <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new_sans_icarus), 
    nb_salaries = sum(a2tot*poids_new_sans_icarus),
    nb_heures = sum(c3tot*poids_new_sans_icarus)
  ) %>% 
  mutate(taille_jaune = "Ensemble")

tableau2_b_new <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new), 
    nb_salaries = sum(a2tot*poids_new),
    nb_heures = sum(c3tot*poids_new)
  ) %>% 
  mutate(taille_jaune = "Ensemble")

tableau2a <- tableau2_a_old |> 
  left_join(
    tableau2_a_inter,
    by = "taille_jaune",
    suffix = c("_old", "_inter")
  ) |>
  left_join(
    tableau2_a_new_sans_icarus |>
      rename_with(~ paste0(.x, "_new_sans_icarus"), -taille_jaune),
    by = "taille_jaune"
  ) |>
  left_join(
    tableau2_a_new |>
      rename_with(~ paste0(.x, "_new"), -taille_jaune),
    by = "taille_jaune"
  )


tableau2b <- tableau2_b_old |> 
  left_join(
    tableau2_b_inter,
    by = "taille_jaune",
    suffix = c("_old", "_inter")
  ) |>
  left_join(
    tableau2_b_new_sans_icarus |>
      rename_with(~ paste0(.x, "_new_sans_icarus"), -taille_jaune),
    by = "taille_jaune"
  ) |>
  left_join(
    tableau2_b_new |>
      rename_with(~ paste0(.x, "_new"), -taille_jaune),
    by = "taille_jaune"
  )

tableau2 <- bind_rows(tableau2a, tableau2b) %>% 
  mutate(
    tx_acces_old = round(nb_formes_old*100/nb_salaries_old,1),
    heures_par_forme_old = round(nb_heures_old/nb_formes_old,1),
    tx_acces_inter = round(nb_formes_inter*100/nb_salaries_inter,1),
    heures_par_forme_inter = round(nb_heures_inter/nb_formes_inter,1),
    tx_acces_new_sans_icarus = round(nb_formes_new_sans_icarus*100/nb_salaries_new_sans_icarus,1),
    heures_par_forme_new_sans_icarus = round(nb_heures_new_sans_icarus/nb_formes_new_sans_icarus,1),
    tx_acces_new = round(nb_formes_new*100/nb_salaries_new,1),
    heures_par_forme_new = round(nb_heures_new/nb_formes_new,1),
    taille_jaune = factor(taille_jaune, levels = c(
      "Moins de 50 salariés",
      "De 50 à 249 salariés",
      "De 250 à 999 salariés",
      "1000 salariés ou plus",
      "Ensemble")
    )
  ) %>% 
  arrange(taille_jaune) %>% 
  select(-starts_with("nb"))
# tableau2
gt_table_taille <- tableau2 |>
  gt(rowname_col = "taille_jaune") |>

  # Titre et sous-titre
  tab_header(
    title = md("**Taux d’accès et durée de formation selon la taille d’entreprise – EFE 2024**"),
    subtitle = md("Comparaison pondérations anciennes, intermédiaires et nouvelles")
  ) |>

  # Labels des colonnes
  cols_label(
    tx_acces_old = "Taux d’accès (Ancienne)",
    heures_par_forme_old = "Heures par formation (Ancienne)",
    tx_acces_inter = "Taux d’accès (Intermédiaire)",
    heures_par_forme_inter = "Heures par formation (Intermédiaire)",
    tx_acces_new_sans_icarus = "Taux d’accès (Nouvelle sans icarus)",
    heures_par_forme_new_sans_icarus = "Heures par formation (Nouvelle sans icarus)",
    tx_acces_new = "Taux d’accès (Nouvelle)",
    heures_par_forme_new = "Heures par formation (Nouvelle)"
  ) |>

  # Format numérique
  fmt_number(
    columns = everything() |> setdiff("taille_jaune"),
    decimals = 1
  ) |>

  # Centrage
  tab_style(
    style = cell_text(align = "center"),
    locations = list(
      cells_column_labels(everything()),
      cells_body(everything())
    )
  ) |>

  # Largeur des colonnes
  cols_width(
    everything() ~ px(140)
  ) |>

  # === COULEURS PAR PONDÉRATION (COLONNES) ===
  tab_style(
    style = cell_fill(color = "#7fb7df"),
    locations = cells_body(columns = c(tx_acces_old, heures_par_forme_old))
  ) |>
  tab_style(
    style = cell_fill(color = "#328ccc"),
    locations = cells_body(columns = c(tx_acces_inter, heures_par_forme_inter))
  ) |>
   tab_style(
    style = cell_fill(color = "#1f6fa3"),
    locations = cells_body(columns = c(tx_acces_new_sans_icarus, heures_par_forme_new_sans_icarus))
  ) |> 
  tab_style(
    style = cell_fill(color = "#0b4f6c"),
    locations = cells_body(columns = c(tx_acces_new, heures_par_forme_new))
  ) |>

  # Texte blanc et gras
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything() |> setdiff("taille_jaune"))
  ) |>

  tab_options(
    data_row.padding = px(8)
  )

gt_table_taille
Taux d’accès et durée de formation selon la taille d’entreprise – EFE 2024
Comparaison pondérations anciennes, intermédiaires et nouvelles
Taux d’accès (Ancienne) Heures par formation (Ancienne) Taux d’accès (Intermédiaire) Heures par formation (Intermédiaire) Taux d’accès (Nouvelle sans icarus) Heures par formation (Nouvelle sans icarus) Taux d’accès (Nouvelle) Heures par formation (Nouvelle)
Moins de 50 salariés 22.1 42.8 21.9 41.9 21.4 43.0 21.1 43.9
De 50 à 249 salariés 44.3 30.8 44.0 30.9 43.9 30.6 44.5 29.8
De 250 à 999 salariés 59.9 26.9 60.4 26.7 60.1 26.4 59.9 26.5
1000 salariés ou plus 70.6 28.3 70.7 28.2 70.8 27.9 69.7 27.9
Ensemble 43.7 31.6 43.8 31.3 43.5 31.2 43.2 31.2

4.3 Taux d’accès par secteur

# Tableau 3: taux d'accès par secteur en 2024 ----------------------------------------

tableau3_a_old <- data %>% 
  group_by(secteur_jaune_lib) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_old), 
    nb_salaries = sum(a2tot*poids_old),
    nb_heures = sum(c3tot*poids_old)
  ) |> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))

tableau3_a_inter <- data %>% 
  group_by(secteur_jaune_lib) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_inter), 
    nb_salaries = sum(a2tot*poids_inter),
    nb_heures = sum(c3tot*poids_inter)
  ) |> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))

tableau3_a_new_sans_icarus <- data %>% 
  group_by(secteur_jaune_lib) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new_sans_icarus), 
    nb_salaries = sum(a2tot*poids_new_sans_icarus),
    nb_heures = sum(c3tot*poids_new_sans_icarus)
  ) |> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))



tableau3_a_new <- data %>% 
  group_by(secteur_jaune_lib) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new), 
    nb_salaries = sum(a2tot*poids_new),
    nb_heures = sum(c3tot*poids_new)
  ) |> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))



tableau3_a <- tableau3_a_old |> 
  left_join(
    tableau3_a_inter,
    by = "secteur_jaune_lib",
    suffix = c("_old", "_inter")
  ) |>
  left_join(
    tableau3_a_new_sans_icarus |>
      rename_with(~ paste0(.x, "_new_sans_icarus"), -secteur_jaune_lib),
    by = "secteur_jaune_lib"
  ) |>
  left_join(
    tableau3_a_new |>
      rename_with(~ paste0(.x, "_new"), -secteur_jaune_lib),
    by = "secteur_jaune_lib"
  )




tableau3_b_old <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_old), 
    nb_salaries = sum(a2tot*poids_old),
    nb_heures = sum(c3tot*poids_old)
  ) %>% 
  mutate(secteur_jaune_lib = "Ensemble")  |> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))

tableau3_b_inter <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_inter), 
    nb_salaries = sum(a2tot*poids_inter),
    nb_heures = sum(c3tot*poids_inter)
  ) %>% 
  mutate(secteur_jaune_lib = "Ensemble")|> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))


tableau3_b_new_sans_icarus <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new_sans_icarus), 
    nb_salaries = sum(a2tot*poids_new_sans_icarus),
    nb_heures = sum(c3tot*poids_new_sans_icarus)
  ) %>% 
  mutate(secteur_jaune_lib = "Ensemble")|> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))




tableau3_b_new <- data %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new), 
    nb_salaries = sum(a2tot*poids_new),
    nb_heures = sum(c3tot*poids_new)
  ) %>% 
  mutate(secteur_jaune_lib = "Ensemble")|> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))



tableau3_b <- tableau3_b_old |> 
  left_join(
    tableau3_b_inter,
    by = "secteur_jaune_lib",
    suffix = c("_old", "_inter")
  ) |>
  left_join(
    tableau3_b_new_sans_icarus |>
      rename_with(~ paste0(.x, "_new_sans_icarus"), -secteur_jaune_lib),
    by = "secteur_jaune_lib"
  ) |> 
  left_join(
    tableau3_b_new |>
      rename_with(~ paste0(.x, "_new"), -secteur_jaune_lib),
    by = "secteur_jaune_lib"
  )





tableau3_c_old <- data %>% 
  filter(tertiaire == 1 ) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_old), 
    nb_salaries = sum(a2tot*poids_old),
    nb_heures = sum(c3tot*poids_old)
  )  %>% 
  mutate(secteur_jaune_lib = "Tertiaire, dont:")|> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))

tableau3_c_inter <- data %>% 
  filter(tertiaire == 1 ) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_inter), 
    nb_salaries = sum(a2tot*poids_inter),
    nb_heures = sum(c3tot*poids_inter)
  )  %>% 
  mutate(secteur_jaune_lib = "Tertiaire, dont:")|> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))

tableau3_c_new_sans_icarus <- data %>% 
  filter(tertiaire == 1 ) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new_sans_icarus), 
    nb_salaries = sum(a2tot*poids_new_sans_icarus),
    nb_heures = sum(c3tot*poids_new_sans_icarus)
  )  %>% 
  mutate(secteur_jaune_lib = "Tertiaire, dont:")|> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))


tableau3_c_new <- data %>% 
  filter(tertiaire == 1 ) %>% 
  summarise(
    nb_formes = sum(c1tot*poids_new), 
    nb_salaries = sum(a2tot*poids_new),
    nb_heures = sum(c3tot*poids_new)
  )  %>% 
  mutate(secteur_jaune_lib = "Tertiaire, dont:")|> 
  mutate(    tx_acces = round(nb_formes*100/nb_salaries,1),
             heures_par_forme = round(nb_heures/nb_formes,1))






tableau3_c <- tableau3_c_old |> 
  left_join(
    tableau3_c_inter,
    by = "secteur_jaune_lib",
    suffix = c("_old", "_inter")
  ) |>
  left_join(
    tableau3_c_new_sans_icarus |>
      rename_with(~ paste0(.x, "_new_sans_icarus"), -secteur_jaune_lib),
    by = "secteur_jaune_lib"
  ) |> 
  left_join(
    tableau3_c_new |>
      rename_with(~ paste0(.x, "_new"), -secteur_jaune_lib),
    by = "secteur_jaune_lib"
  )

tableau3 <- bind_rows(tableau3_a, tableau3_b) %>% 
  bind_rows(tableau3_c) %>% 
  mutate(
    secteur_jaune_lib = factor(secteur_jaune_lib, levels = c(
      "Agriculture",
      "Industrie",
      "Construction",
      "Tertiaire, dont:",
      "Commerce et réparation d'automobiles",
      "Transports et entreposage",
      "Hébergement et restauration",
      "Information et communication",
      "Activités financières et d'assurance",
      "Activités immobilières et scientifiques",
      "Services administratifs et de soutien",
      "Arts et spectacles",
      "Enseignement et santé",
      "Ensemble")
    )
  ) %>% 
  arrange(secteur_jaune_lib) %>% 
  select(-starts_with("nb"))
# tableau3
gt_table_secteur_tx <- tableau3 |>
  gt(rowname_col = "secteur_jaune_lib") |>

  # Titre et sous-titre
  tab_header(
    title = md("**Taux d’accès et durée de formation par secteur – EFE 2024**"),
    subtitle = md("Comparaison pondérations anciennes, intermédiaires et nouvelles")
  ) |>

  # Labels des colonnes
  cols_label(
    tx_acces_old = "Taux d’accès",
    heures_par_forme_old = "Heures/formation",
    tx_acces_inter = "Taux d’accès",
    heures_par_forme_inter = "Heures/formation",
    tx_acces_new_sans_icarus = "Taux d’accès",
    heures_par_forme_new_sans_icarus = "Heures/formation",
    tx_acces_new = "Taux d’accès",
    heures_par_forme_new = "Heures/formation"
  ) |>

  # Spanners par pondération
  tab_spanner("Ancienne", c(tx_acces_old, heures_par_forme_old)) |>
  tab_spanner("Intermédiaire", c(tx_acces_inter, heures_par_forme_inter)) |>
  tab_spanner("Nouvelle sans Icarus", c(tx_acces_new_sans_icarus, heures_par_forme_new_sans_icarus)) |>
  tab_spanner("Nouvelle", c(tx_acces_new, heures_par_forme_new)) |>

  # Format numérique
  fmt_number(
    columns = everything() |> setdiff("secteur_jaune_lib"),
    decimals = 1
  ) |>

  # Centrage
  tab_style(
    style = cell_text(align = "center"),
    locations = list(
      cells_column_labels(everything()),
      cells_body(everything())
    )
  ) |>

  # Largeur des colonnes
  cols_width(
    everything() ~ px(140)
  ) |>

  # === COULEURS PAR PONDÉRATION (COLONNES) ===
  tab_style(
    style = cell_fill(color = "#7fb7df"),
    locations = cells_body(columns = c(tx_acces_old, heures_par_forme_old))
  ) |>
  tab_style(
    style = cell_fill(color = "#328ccc"),
    locations = cells_body(columns = c(tx_acces_inter, heures_par_forme_inter))
  ) |>
  tab_style(
    style = cell_fill(color = "#1f6fa3"),
    locations = cells_body(columns = c(tx_acces_new_sans_icarus, heures_par_forme_new_sans_icarus))
  ) |>
  tab_style(
    style = cell_fill(color = "#0b4f6c"),
    locations = cells_body(columns = c(tx_acces_new, heures_par_forme_new))
  ) |>

  # Texte blanc et gras
  tab_style(
    style = cell_text(color = "white", weight = "bold"),
    locations = cells_body(columns = everything() |> setdiff("secteur_jaune_lib"))
  ) |>

  tab_options(
    data_row.padding = px(8)
  )

gt_table_secteur_tx
Taux d’accès et durée de formation par secteur – EFE 2024
Comparaison pondérations anciennes, intermédiaires et nouvelles
Ancienne
Intermédiaire
Nouvelle sans Icarus
Nouvelle
Taux d’accès Heures/formation Taux d’accès Heures/formation Taux d’accès Heures/formation Taux d’accès Heures/formation
Agriculture 20.6 29.7 20.8 27.3 22.8 24.2 22.9 24.5
Industrie 55.7 33.9 55.8 33.8 56.5 35.1 56.5 34.9
Construction 32.4 35.3 32.0 34.8 31.4 32.8 30.2 33.4
Tertiaire, dont: 43.1 30.7 43.2 30.4 42.6 30.1 42.3 30.2
Commerce et réparation d'automobiles 39.7 23.5 39.1 23.3 37.8 22.0 37.6 22.1
Transports et entreposage 53.7 28.4 55.7 29.1 55.4 29.2 53.8 28.2
Hébergement et restauration 19.4 27.3 19.0 27.5 18.2 26.1 18.6 25.8
Information et communication 52.8 27.5 52.9 26.6 52.3 26.4 50.6 27.5
Activités financières et d'assurance 76.0 33.2 76.3 33.4 76.2 33.1 77.5 32.8
Activités immobilières et scientifiques 46.7 29.5 46.4 29.0 46.1 28.2 45.1 28.6
Services administratifs et de soutien 32.7 31.8 32.0 30.9 32.4 31.1 33.0 29.5
Arts et spectacles 33.9 39.5 34.6 38.8 32.9 39.0 34.1 38.6
Enseignement et santé 49.4 38.8 50.0 37.6 49.3 38.5 48.4 39.9
Ensemble 43.7 31.6 43.8 31.3 43.5 31.2 43.2 31.2

5- Taux de recours à la formation à distance des structures formatrices, selon la taille

tableau_graphe1_a_old <- data %>% 
  filter(formatrice == 1) %>% 
  group_by( taille_jaune) %>% 
  summarise(
    nb_entreprises = sum(poids_old),
    nb_recours_distance = sum(b1cflag*poids_old)
  ) |> 
  mutate(
    tx_recours_distance = nb_recours_distance*100/nb_entreprises)

tableau_graphe1_a_inter <- data %>% 
  filter(formatrice == 1) %>% 
  group_by( taille_jaune) %>% 
  summarise(
    nb_entreprises = sum(poids_inter),
    nb_recours_distance = sum(b1cflag*poids_inter)
  ) |> 
  mutate(
    tx_recours_distance = nb_recours_distance*100/nb_entreprises)


tableau_graphe1_a_new_sans_icarus <- data %>% 
  filter(formatrice == 1) %>% 
  group_by( taille_jaune) %>% 
  summarise(
    nb_entreprises = sum(poids_new_sans_icarus),
    nb_recours_distance = sum(b1cflag*poids_new_sans_icarus)
  ) |> 
  mutate(
    tx_recours_distance = nb_recours_distance*100/nb_entreprises)

tableau_graphe1_a_new <- data %>% 
  filter(formatrice == 1) %>% 
  group_by( taille_jaune) %>% 
  summarise(
    nb_entreprises = sum(poids_new),
    nb_recours_distance = sum(b1cflag*poids_new)
  ) |> 
  mutate(
    tx_recours_distance = nb_recours_distance*100/nb_entreprises)


tableau_graphe1_a <- tableau_graphe1_a_old |> 
  left_join(
    tableau_graphe1_a_inter,
    by = "taille_jaune",
    suffix = c("_old", "_inter")
  ) |>
  left_join(
    tableau_graphe1_a_new_sans_icarus |>
      rename_with(~ paste0(.x, "_new_sans_icarus"), -taille_jaune),
    by = "taille_jaune"
  ) |> 
  left_join(
    tableau_graphe1_a_new |>
      rename_with(~ paste0(.x, "_new"), -taille_jaune),
    by = "taille_jaune"
  )
# tableau_graphe1_a

tableau_graphe1_b_old <- data %>% 
  filter(formatrice == 1) %>% 
  summarise(
    nb_entreprises = sum(poids_old),
    nb_recours_distance = sum(b1cflag*poids_old)
  ) %>% 
  mutate(taille_jaune = "Ensemble")|> 
  mutate(
    tx_recours_distance = nb_recours_distance*100/nb_entreprises)


tableau_graphe1_b_inter <- data %>% 
  filter(formatrice == 1) %>% 
  summarise(
    nb_entreprises = sum(poids_inter),
    nb_recours_distance = sum(b1cflag*poids_inter)
  ) %>% 
  mutate(taille_jaune = "Ensemble")|> 
  mutate(
    tx_recours_distance = nb_recours_distance*100/nb_entreprises)


tableau_graphe1_b_new_sans_icarus <- data %>% 
  filter(formatrice == 1) %>% 
  summarise(
    nb_entreprises = sum(poids_new_sans_icarus),
    nb_recours_distance = sum(b1cflag*poids_new_sans_icarus)
  ) %>% 
  mutate(taille_jaune = "Ensemble") |> 
  mutate(
    tx_recours_distance = nb_recours_distance*100/nb_entreprises)



tableau_graphe1_b_new <- data %>% 
  filter(formatrice == 1) %>% 
  summarise(
    nb_entreprises = sum(poids_new),
    nb_recours_distance = sum(b1cflag*poids_new)
  ) %>% 
  mutate(taille_jaune = "Ensemble") |> 
  mutate(
  tx_recours_distance = nb_recours_distance*100/nb_entreprises)

tableau_graphe1_b <- tableau_graphe1_b_old |> 
  left_join(
    tableau_graphe1_b_inter,
    by = "taille_jaune",
    suffix = c("_old", "_inter")
  ) |>
  left_join(
    tableau_graphe1_b_new_sans_icarus |>
      rename_with(~ paste0(.x, "_new_sans_icarus"), -taille_jaune),
    by = "taille_jaune"
  ) |> 
  left_join(
    tableau_graphe1_b_new |>
      rename_with(~ paste0(.x, "_new"), -taille_jaune),
    by = "taille_jaune"
  )

# tableau_graphe1_b
  
tableau_graphe1 <- bind_rows(tableau_graphe1_a, tableau_graphe1_b) %>% 
  mutate(
    taille_jaune = factor(taille_jaune, levels = c(
      "Moins de 50 salariés",
      "De 50 à 249 salariés",
      "De 250 à 999 salariés",
      "1000 salariés ou plus",
      "Ensemble")
    )
  ) 
 # tableau_graphe1

graphe1 <- ggplot(tableau_graphe1,
       aes(x = taille_jaune,
           y = round(tx_recours_distance_old/100,2),
           label = round(tx_recours_distance_old,0)
           )) +
  geom_col(width = 0.7, position = position_dodge(0.8)) +
  geom_text(position = position_dodge(.8), vjust = -0.5, color = "grey30", size = 3) +
  theme_minimal() +
  xlab("") +
  ylab("") +
  theme(
    #text=element_text(family="Marianne"),
    legend.title=element_blank(),
    panel.grid.minor.y = element_blank(),
    panel.grid.major.x = element_blank()
  ) +
  scale_y_continuous(
    limits = c(0,1),
    breaks = c(0, 0.2, 0.4, 0.6, 0.8, 1),
    labels = scales::percent
  ) +
  scale_x_discrete(labels = scales::label_wrap(15)) +
  scale_fill_manual(values=c("#7fb7df", "#328ccc")) 
tableau_graphe1_long <- tableau_graphe1 |>
  pivot_longer(
    cols = c(
      tx_recours_distance_old,
      tx_recours_distance_inter,
      tx_recours_distance_new_sans_icarus,
      tx_recours_distance_new
    ),
    names_to = "periode",
    values_to = "tx"
  )
tableau_graphe1_long <- tableau_graphe1_long |>
  mutate(
    periode = factor(
      periode,
      levels = c(
        "tx_recours_distance_old",
        "tx_recours_distance_inter",
        "tx_recours_distance_new_sans_icarus",
        "tx_recours_distance_new"
      ),
      labels = c("Ancien", "Intermédiaire","Nouveau sans Icarus", "Nouveau")
    )
  )


graphe1 <- ggplot(
  tableau_graphe1_long,
  aes(
    x = taille_jaune,
    y = round(tx / 100, 2),
    fill = periode,
    label = round(tx, 0)
  )
) +
  geom_col(
    width = 0.7,
    position = position_dodge(0.8)
  ) +
  geom_text(
    position = position_dodge(0.8),
    vjust = -0.5,
    color = "grey30",
    size = 3,
    #family = "Marianne"
  ) +
  theme_minimal() +
  xlab("") +
  ylab("") +
  theme(
   # text = element_text(family = "Marianne"),
    legend.title = element_blank(),
    panel.grid.minor.y = element_blank(),
    panel.grid.major.x = element_blank()
  ) +
  scale_y_continuous(
    limits = c(0, 1),
    breaks = c(0, 0.2, 0.4, 0.6, 0.8, 1),
    labels = scales::percent
  ) +
  scale_x_discrete(labels = scales::label_wrap(15)) +
  scale_fill_manual(
    values = c(
      "Ancien"        = "#7fb7df",
      "Intermédiaire" = "#328ccc",
      "Nouveau sans Icarus" = "#1f6fa3",
      "Nouveau"       = "#0b4f6c"
    )
  )
  

  
###############
graphe1 <- graphe1 + labs(  title = "Taux de recours à la formation par taille")
graphe1

6- Part d’heures de formation relevant de formations obligatoires selon le secteur de l’entreprise formatrice

# Graphe 2 ---------------------------------------------------------------------
# Part d’heures de formation relevant de formations obligatoires selon le secteur de l’entreprise formatrice
# en 2024

tableau_graphe2_a <- data %>% 
  filter(formatrice == 1 ) %>% 
  group_by(secteur_jaune_lib) %>% 
  summarise(
    tot_heures_old = sum(c3tot*poids_old),
    tot_heures_oblig_old = sum(heures_oblig*poids_old),
    
    tot_heures_inter = sum(c3tot*poids_inter),
    tot_heures_oblig_inter = sum(heures_oblig*poids_inter),
    
    tot_heures_new_sans_icarus = sum(c3tot*poids_new_sans_icarus),
    tot_heures_oblig_new_sans_icarus = sum(heures_oblig*poids_new_sans_icarus), 
    
    tot_heures_new = sum(c3tot*poids_new),
    tot_heures_oblig_new = sum(heures_oblig*poids_new), 
    
    part_oblig_old = tot_heures_oblig_old*100/tot_heures_old,
    part_oblig_inter = tot_heures_oblig_inter*100/tot_heures_inter,
    part_oblig_new_sans_icarus = tot_heures_oblig_new_sans_icarus*100/tot_heures_new_sans_icarus,
    part_oblig_new = tot_heures_oblig_new*100/tot_heures_new,
    
  ) 
# tableau_graphe2_a

tableau_graphe2_b <- data %>% 
  filter(formatrice == 1 ) %>% 
  summarise(
    tot_heures_old = sum(c3tot*poids_old),
    tot_heures_oblig_old = sum(heures_oblig*poids_old),
    
    tot_heures_inter = sum(c3tot*poids_inter),
    tot_heures_oblig_inter = sum(heures_oblig*poids_inter),
    
    tot_heures_new_sans_icarus = sum(c3tot*poids_new_sans_icarus),
    tot_heures_oblig_new_sans_icarus = sum(heures_oblig*poids_new_sans_icarus),
    
    tot_heures_new = sum(c3tot*poids_new),
    tot_heures_oblig_new = sum(heures_oblig*poids_new),
    
    part_oblig_old = tot_heures_oblig_old*100/tot_heures_old,
    part_oblig_inter = tot_heures_oblig_inter*100/tot_heures_inter,
    part_oblig_new_sans_icarus = tot_heures_oblig_new_sans_icarus*100/tot_heures_new_sans_icarus,
    part_oblig_new = tot_heures_oblig_new*100/tot_heures_new,
  ) %>% 
  mutate(secteur_jaune_lib = "Ensemble")

tableau_graphe2 <- bind_rows(tableau_graphe2_a, tableau_graphe2_b) %>% 
  mutate(
    secteur_jaune_lib = factor(secteur_jaune_lib, levels = c(
      "Construction",
      "Transports et entreposage",
      "Hébergement et restauration",
      "Agriculture",
      "Industrie",
      "Commerce et réparation d'automobiles",
      "Arts et spectacles",
      "Activités financières et d'assurance",
      "Services administratifs et de soutien",
      "Activités immobilières et scientifiques",
      "Enseignement et santé",
      "Information et communication",
      "Ensemble")
    )
  ) %>% 
  arrange(secteur_jaune_lib) 
# tableau_graphe2


tableau_graphe2_long <- tableau_graphe2 |>
  pivot_longer(
    cols = c(
      part_oblig_old,
      part_oblig_inter,
      part_oblig_new_sans_icarus,
      part_oblig_new
    ),
    names_to = "periode",
    values_to = "part"
  ) |>
  mutate(
    periode = factor(
      periode,
      levels = c(
        "part_oblig_old",
        "part_oblig_inter",
        "part_oblig_new_sans_icarus",
        "part_oblig_new"
      ),
      labels = c("Ancien", "Intermédiaire", "Nouveau sans Icarus", "Nouveau")
    )
  )
graphe2 <- ggplot(
  tableau_graphe2_long,
  aes(
    x = secteur_jaune_lib,
    y = round(part / 100, 2),
    fill = periode,
    label = round(part, 0)
  )
) +
  geom_col(
    width = 0.7,
    position = position_dodge(0.8)
  ) +
  coord_flip() +
  geom_text(
    position = position_dodge(0.8),
    hjust = -0.2,
    vjust = 0.5,
    color = "grey30",
    size = 3,
    #family = "Marianne"
  ) +
  theme_minimal() +
  xlab("") +
  ylab("") +
  theme(
   # text = element_text(family = "Marianne"),
    legend.title = element_blank(),
    panel.grid.minor.x = element_blank(),
    panel.grid.major.y = element_blank(),
    panel.grid.minor.y = element_blank(),
    axis.text.y = element_text(size = 10)
  ) +
  scale_y_continuous(
    limits = c(0, 0.45),
    breaks = c(0, 0.1, 0.2, 0.3, 0.4),
    labels = scales::percent
  ) +
  scale_x_discrete(limits = rev) +
  scale_fill_manual(
    values = c(
      "Ancien"        = "#7fb7df",
      "Intermédiaire" = "#328ccc",
      "Nouveau sans Icarus" = "#1f6fa3",
      "Nouveau"       = "#0b4f6c"
    )
  )
graphe2 <- graphe2 +
  guides(fill = guide_legend(reverse = TRUE)) 
graphe2 <- graphe2 +
  labs(
    title = "Taux de recours à la formation par secteur") +
   theme(
    legend.position = "bottom"
  )

graphe2

######