修订版 | 121264f50667afc4b3b8d98d5ef6e5b00927c73c (tree) |
---|---|
时间 | 2023-02-08 00:55:18 |
作者 | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
I replaced most of the %>% with |>, but one is still missing.
@@ -28,157 +28,11 @@ | ||
28 | 28 | source("/home/lorenzo/myprojects-hg/R-codes/stat_lib.R") |
29 | 29 | |
30 | 30 | |
31 | -## iso_map <- tibble(iso3=c("AUT", "BEL", "BGR", "CYP", "CZE", "DEU", "DNK", "ESP", "EST", "FIN", | |
32 | -## "FRA", | |
33 | -## "GRC", "HRV", "HUN", "IRL", "ITA", "LTU", "LUX", "LVA", "MLT", | |
34 | -## "NLD", "POL", "PRT", | |
35 | -## "ROM", "SVK", "SVN", "SWE"), | |
36 | -## country=c("Austria", "Belgium", "Bulgaria", "Cyprus", "Czech Republic", "Germany", | |
37 | -## "Denmark", "Spain", "Estonia", "Finland", "France", "Greece", | |
38 | -## "Croatia", "Hungary", "Ireland","Italy", "Lituania", "Luxembourg", | |
39 | -## "Latvia", "Malta", "Netherlands", "Poland", "Portugal", | |
40 | -## "Romania", "Slovakia", "Slovenia", "Sweden") | |
41 | -## ) | |
42 | - | |
43 | -## add_total <- function(x, pos=1, ...){ | |
44 | -## adorn_totals(x, ...) %>% as_tibble %>% | |
45 | -## move_row(nrow(.), pos) | |
46 | -## } | |
47 | - | |
48 | -## add_total <- function(x, pos=1, ...){ | |
49 | -## x <- as_tibble(x) | |
50 | - | |
51 | -## adorn_totals(x, ...) |> | |
52 | -## as_tibble() |> | |
53 | -## move_row(nrow(.), pos) | |
54 | -## } | |
55 | - | |
56 | - | |
57 | -## add_total <- function(x, pos=1, ...){ | |
58 | - | |
59 | - | |
60 | - | |
61 | -## x |> as_tibble() |> | |
62 | -## adorn_totals( ...) |> | |
63 | -## as_tibble() |> | |
64 | -## (\(x) move_row(x, nrow(x)+1, pos))() | |
65 | - | |
66 | -## } | |
67 | - | |
68 | - | |
69 | - | |
70 | -## iso_map <- tibble(iso3=c("AUT", "BEL", "BGR", "CYP", "CZE", "DEU", "DNK", "ESP", "EST", "FIN", | |
71 | -## "FRA", | |
72 | -## "GRC", "HRV", "HUN", "IRL", "ITA", "LTU", "LUX", "LVA", "MLT", | |
73 | -## "NLD", "POL", "PRT", | |
74 | -## "ROM", "SVK", "SVN", "SWE", "GBR"), | |
75 | -## iso2 = c("AT", "BE", "BG", "CY", "CZ","DE", | |
76 | -## "DK", "ES" ,"EE", "FI", "FR", "EL", "HR", "HU", "IE", | |
77 | -## "IT" , "LT","LU", "LV", "MT", "NL", "PL", | |
78 | -## "PT", "RO", "SK", "SI", "SE", "UK"), | |
79 | - | |
80 | -## country=c("Austria", "Belgium", "Bulgaria", "Cyprus", "Czechia", "Germany", | |
81 | -## "Denmark", "Spain", "Estonia", "Finland", "France", "Greece", | |
82 | -## "Croatia", "Hungary", "Ireland","Italy", "Lithuania", "Luxembourg", | |
83 | -## "Latvia", "Malta", "Netherlands", "Poland", "Portugal", | |
84 | -## "Romania", "Slovakia", "Slovenia", "Sweden", "United Kingdom") | |
85 | -## ) | |
86 | - | |
87 | 31 | |
88 | 32 | |
89 | 33 | # Suppress summarise info |
90 | 34 | options(dplyr.summarise.inform = FALSE) |
91 | 35 | |
92 | -## '%!in%' <- function(x,y)!('%in%'(x,y)) | |
93 | - | |
94 | - | |
95 | - | |
96 | -## format_col <- function(x, n, my_sep=" "){ | |
97 | - | |
98 | -## res <- format(round(x, n), nsmall = n, big.mark= my_sep, trim=TRUE ) | |
99 | - | |
100 | -## return(res) | |
101 | - | |
102 | -## } | |
103 | - | |
104 | - | |
105 | -## recode_many <- function(x, old_names, new_names){ | |
106 | - | |
107 | -## name_lookup <- set_names(new_names, old_names) %>% as.list | |
108 | - | |
109 | -## res <- recode(x, !!!name_lookup) | |
110 | -## return(res) | |
111 | - | |
112 | -## } | |
113 | - | |
114 | - | |
115 | -## my_ggplot_theme2 <- function(legend_coord){ | |
116 | -## theme_bw()+ | |
117 | - | |
118 | -## theme(## legend.title = element_text(vjust=1,lineheight=1, size=14 ), | |
119 | - | |
120 | -## legend.title = element_text(vjust = 1,lineheight=1, | |
121 | -## size=14, margin = margin(t = 4.5)), | |
122 | -## legend.spacing.y = grid::unit(3, "pt"), | |
123 | -## legend.text.align = 0.5, | |
124 | - | |
125 | -## panel.grid.minor = element_blank(), | |
126 | -## plot.title = element_text(lineheight=.8, size=24, face="bold", | |
127 | -## vjust=1),legend.text = element_text(vjust=.4,lineheight=1,size = 14 ), | |
128 | -## axis.title.x = element_text(size = 20, vjust=1), | |
129 | -## axis.title.y = element_text(size = 20, angle=90, vjust=1), | |
130 | -## axis.text.x = element_text(size=15, colour="black", vjust=1), | |
131 | -## axis.text.y = element_text(size=15, colour="black", hjust=1), | |
132 | -## legend.position = legend_coord, | |
133 | -## strip.background = element_rect(colour = 'blue', | |
134 | -## fill = 'white', size = 1, linetype=1), | |
135 | -## strip.text.x = element_text(colour = 'red', angle = 0, | |
136 | -## size = 12, hjust = 0.5, | |
137 | -## vjust = 0.5, face = 'bold'), | |
138 | -## strip.text.y = element_text(colour = 'red', angle = 0, | |
139 | -## size = 12, hjust = 0.5, | |
140 | -## vjust = 0.5, face = 'bold'), | |
141 | - | |
142 | -## ) | |
143 | -## } | |
144 | - | |
145 | - | |
146 | - | |
147 | - | |
148 | -## round_preserve_sum <- function(x, digits = 0) { | |
149 | -## up <- 10^digits | |
150 | -## x <- x * up | |
151 | -## y <- floor(x) | |
152 | -## indices <- tail(order(x-y), round(sum(x, na.rm=T)) - sum(y, na.rm=T)) | |
153 | -## y[indices] <- y[indices] + 1 | |
154 | -## y / up | |
155 | -## } | |
156 | - | |
157 | - | |
158 | -## ##a function to move a row in a data frame. | |
159 | - | |
160 | -## move_row <- function(df, ini_pos, fin_pos){ | |
161 | - | |
162 | -## ll <- nrow(df) | |
163 | - | |
164 | -## row_pick <- slice(df, ini_pos) | |
165 | - | |
166 | -## if (fin_pos=="last"){ | |
167 | - | |
168 | -## res <- df %>% | |
169 | -## slice(-ini_pos) %>% | |
170 | -## add_row(row_pick, .before = ll) | |
171 | - | |
172 | - | |
173 | -## } else{ | |
174 | - | |
175 | -## res <- df %>% | |
176 | -## slice(-ini_pos) %>% | |
177 | -## add_row(row_pick, .before = fin_pos) | |
178 | -## } | |
179 | - | |
180 | -## return(res) | |
181 | -## } | |
182 | 36 | |
183 | 37 | ############################################################################ |
184 | 38 | ############################################################################ |
@@ -190,10 +44,10 @@ | ||
190 | 44 | |
191 | 45 | |
192 | 46 | |
193 | -ms3 <- iso_map_eu28 %>% | |
194 | - filter(iso3==MS) %>% | |
195 | - pull(country) %>% | |
196 | - as.character | |
47 | +ms3 <- iso_map_eu28 |> | |
48 | + filter(iso3==MS) |> | |
49 | + pull(country) |> | |
50 | + as.character() | |
197 | 51 | |
198 | 52 | |
199 | 53 | ## covid_qualifiers <- c( "Covid19-TF", |
@@ -202,7 +56,7 @@ | ||
202 | 56 | ## ) |
203 | 57 | |
204 | 58 | |
205 | -scoreboard <- readRDS("../scoreboard.RDS") %>% | |
59 | +scoreboard <- readRDS("../scoreboard.RDS") |> | |
206 | 60 | filter(!is.na(aid_element_eur)) |> |
207 | 61 | rename("year"="expenditure_year", |
208 | 62 | "amount_spent_aid_element_in_eur_million" ="aid_element_eur", |
@@ -213,24 +67,24 @@ | ||
213 | 67 | ## mutate(member_state=recode_many(member_state,iso_map$country, |
214 | 68 | ## iso_map$iso3 )) |
215 | 69 | |
216 | -scoreboard_ms <- scoreboard %>% | |
70 | +scoreboard_ms <- scoreboard |> | |
217 | 71 | filter(member_state_3_letter_codes==MS) |
218 | 72 | |
219 | -year_focus <- scoreboard_ms %>% | |
220 | - pull(year) %>% | |
73 | +year_focus <- scoreboard_ms |> | |
74 | + pull(year) |> | |
221 | 75 | max() |
222 | 76 | |
223 | 77 | |
224 | 78 | ini_focus <- year_focus-10 |
225 | 79 | |
226 | 80 | |
227 | -cases <- scoreboard_ms %>% | |
81 | +cases <- scoreboard_ms |> | |
228 | 82 | filter(year==max(year), |
229 | 83 | ## duration_end>=max(year), |
230 | 84 | amount_spent_aid_element_in_eur_million>0 |
231 | - )%>% | |
85 | + ) |> | |
232 | 86 | select(member_state_3_letter_codes,case_no, year,amount_spent_aid_element_in_eur_million, |
233 | - procedure_name) %>% | |
87 | + procedure_name) |> | |
234 | 88 | ## filter(grepl("SA.", case_no)) %>% |
235 | 89 | distinct(case_no,.keep_all =T ) |
236 | 90 |
@@ -238,24 +92,24 @@ | ||
238 | 92 | |
239 | 93 | |
240 | 94 | |
241 | -total_amount_eu27 <- scoreboard %>% | |
95 | +total_amount_eu27 <- scoreboard |> | |
242 | 96 | filter(year==max(year), |
243 | 97 | ## duration_end>=max(year), |
244 | 98 | amount_spent_aid_element_in_eur_million>0, |
245 | 99 | member_state_3_letter_codes %in% iso_map_eu27$iso3 |
246 | - ) %>% | |
100 | + ) |> | |
247 | 101 | summarise(total=sum(amount_spent_aid_element_in_eur_million)) |
248 | 102 | |
249 | 103 | |
250 | 104 | |
251 | -total_amount_eu27_covid <- scoreboard %>% | |
105 | +total_amount_eu27_covid <- scoreboard |> | |
252 | 106 | filter(year==max(year), |
253 | 107 | ## all_intq %in% covid_qualifiers, |
254 | 108 | covid==T, |
255 | 109 | ## duration_end>=max(year), |
256 | 110 | amount_spent_aid_element_in_eur_million>0, |
257 | 111 | member_state_3_letter_codes %in% iso_map_eu27$iso3 |
258 | - ) %>% | |
112 | + ) |> | |
259 | 113 | summarise(total=sum(amount_spent_aid_element_in_eur_million)) |> |
260 | 114 | ungroup() |
261 | 115 |
@@ -272,7 +126,7 @@ | ||
272 | 126 | ungroup() |
273 | 127 | |
274 | 128 | |
275 | -total_amount_MS_covid <- scoreboard %>% | |
129 | +total_amount_MS_covid <- scoreboard |> | |
276 | 130 | filter(year==max(year), |
277 | 131 | member_state_3_letter_codes==MS, |
278 | 132 | ## all_intq %in% covid_qualifiers, |
@@ -280,38 +134,38 @@ | ||
280 | 134 | ## duration_end>=max(year), |
281 | 135 | amount_spent_aid_element_in_eur_million>0, |
282 | 136 | member_state_3_letter_codes %in% iso_map_eu27$iso3 |
283 | - ) %>% | |
137 | + ) |> | |
284 | 138 | summarise(total=sum(amount_spent_aid_element_in_eur_million)) |> |
285 | 139 | ungroup() |
286 | 140 | |
287 | 141 | |
288 | -covid_summary <- total_amount_eu27 %>% | |
289 | - rename("total_eu"="total") %>% | |
142 | +covid_summary <- total_amount_eu27 |> | |
143 | + rename("total_eu"="total") |> | |
290 | 144 | mutate(total_eu27_covid=total_amount_eu27_covid$total, |
291 | 145 | total_ms=total_amount_MS$total, |
292 | - total_ms_covid=total_amount_MS_covid$total) %>% | |
146 | + total_ms_covid=total_amount_MS_covid$total) |> | |
293 | 147 | mutate(eu_covid_percentage=total_eu27_covid/total_eu, |
294 | 148 | ms_covid_percentage=total_ms_covid/total_ms) |
295 | 149 | |
296 | -covid_summary_long <- covid_summary %>% | |
297 | - select(contains("percentage")) %>% | |
150 | +covid_summary_long <- covid_summary |> | |
151 | + select(contains("percentage")) |> | |
298 | 152 | pivot_longer(cols = c(eu_covid_percentage , |
299 | 153 | ms_covid_percentage |
300 | - ) , names_to= "country", values_to="covid_percentage" ) %>% | |
301 | - mutate(ll=format_col(covid_percentage*100,1)) %>% | |
302 | - mutate(ll=paste(ll, "%", sep="")) %>% | |
303 | - arrange(country) %>% | |
154 | + ) , names_to= "country", values_to="covid_percentage" ) |> | |
155 | + mutate(ll=format_col(covid_percentage*100,1)) |> | |
156 | + mutate(ll=paste(ll, "%", sep="")) |> | |
157 | + arrange(country) |> | |
304 | 158 | mutate(country=fct_inorder(country)) |
305 | 159 | |
306 | 160 | |
307 | 161 | |
308 | 162 | n_cases <- nrow(cases) |
309 | 163 | |
310 | -stat_cases <- cases %>% | |
311 | - tabyl(procedure_name) %>% | |
312 | - mutate(percent=round_preserve_sum(percent*100,1)) %>% | |
313 | - add_total() %>% | |
314 | - mutate(percent=format_col(percent,1)) %>% | |
164 | +stat_cases <- cases |> | |
165 | + tabyl(procedure_name) |> | |
166 | + mutate(percent=round_preserve_sum(percent*100,1)) |> | |
167 | + add_total() |> | |
168 | + mutate(percent=format_col(percent,1)) |> | |
315 | 169 | mutate(percent=paste(percent, "%", sep="")) |
316 | 170 | |
317 | 171 |
@@ -326,38 +180,38 @@ | ||
326 | 180 | |
327 | 181 | |
328 | 182 | |
329 | -old_cases <- scoreboard %>% | |
183 | +old_cases <- scoreboard |> | |
330 | 184 | filter(year>=ini_focus, year!= year_focus, member_state_3_letter_codes==MS) |
331 | 185 | |
332 | 186 | new_cases_list <- setdiff(cases$case_no, old_cases$case_no) |
333 | 187 | |
334 | -cases_new <- scoreboard_ms %>% | |
188 | +cases_new <- scoreboard_ms |> | |
335 | 189 | filter(case_no %in% new_cases_list , |
336 | 190 | ## duration_end>=max(year), |
337 | 191 | amount_spent_aid_element_in_eur_million>0 |
338 | - )%>% | |
192 | + ) |> | |
339 | 193 | select(member_state_3_letter_codes,case_no, year,amount_spent_aid_element_in_eur_million, |
340 | - procedure_name) %>% | |
194 | + procedure_name) |> | |
341 | 195 | ## filter(grepl("SA.", case_no)) %>% |
342 | 196 | distinct(case_no,.keep_all =T ) |
343 | 197 | |
344 | -stat_cases_new <- cases_new %>% | |
345 | - tabyl(procedure_name) %>% | |
198 | +stat_cases_new <- cases_new |> | |
199 | + tabyl(procedure_name) |> | |
346 | 200 | mutate(percent=round(percent*100,1)) |
347 | 201 | |
348 | 202 | |
349 | 203 | if (nrow(stat_cases_new)==0){ |
350 | - stat_cases_new <- stat_cases_new %>% | |
204 | + stat_cases_new <- stat_cases_new |> | |
351 | 205 | add_row(percent=0) |
352 | 206 | |
353 | 207 | |
354 | 208 | } |
355 | 209 | |
356 | -stat_cases2 <- scoreboard %>% | |
357 | - filter(year>=ini_focus, member_state_3_letter_codes==MS) %>% | |
358 | - group_by(year, procedure_name) %>% | |
359 | - summarise(expenditure=sum(amount_spent_aid_element_in_eur_million/1e3)) %>% | |
360 | - ungroup | |
210 | +stat_cases2 <- scoreboard |> | |
211 | + filter(year>=ini_focus, member_state_3_letter_codes==MS) |> | |
212 | + group_by(year, procedure_name) |> | |
213 | + summarise(expenditure=sum(amount_spent_aid_element_in_eur_million/1e3)) |> | |
214 | + ungroup() | |
361 | 215 | |
362 | 216 | |
363 | 217 | ## stat_cases3 <- scoreboard %>% |
@@ -375,69 +229,84 @@ | ||
375 | 229 | ## mutate(percent=paste(percent, "%", sep="")) |
376 | 230 | |
377 | 231 | |
378 | -stat_cases3 <- scoreboard %>% | |
379 | - filter(year>=ini_focus, member_state_3_letter_codes==MS) %>% | |
232 | +stat_cases3 <- scoreboard |> | |
233 | + filter(year>=ini_focus, member_state_3_letter_codes==MS) |> | |
380 | 234 | ## mutate(procedure2=if_else(procedure_name=="General Block Exemption Regulation", "(G)BER", procedure_name)) %>% |
381 | - group_by( procedure_name) %>% | |
382 | - summarise(expenditure=sum(amount_spent_aid_element_in_eur_million)/1e3) %>% | |
383 | - ungroup %>% | |
384 | - mutate(expenditure=round_preserve_sum(expenditure, 1)) %>% | |
385 | - mutate(percent=expenditure/sum(expenditure)*100) %>% | |
386 | - mutate(percent=round_preserve_sum(percent,1)) %>% | |
387 | - add_total() %>% | |
235 | + group_by( procedure_name) |> | |
236 | + summarise(expenditure=sum(amount_spent_aid_element_in_eur_million)/1e3) |> | |
237 | + ungroup() |> | |
238 | + mutate(expenditure=round_preserve_sum(expenditure, 1)) |> | |
239 | + mutate(percent=expenditure/sum(expenditure)*100) |> | |
240 | + mutate(percent=round_preserve_sum(percent,1)) |> | |
241 | + add_total() |> | |
388 | 242 | mutate(percent=format_col(percent,1), |
389 | - expenditure=format_col(expenditure,1)) %>% | |
390 | - mutate(percent=paste(percent,"%", sep="")) %>% | |
243 | + expenditure=format_col(expenditure,1)) |> | |
244 | + mutate(percent=paste(percent,"%", sep="")) |> | |
391 | 245 | mutate(expenditure=if_else(expenditure!="0.0", expenditure,"less than 0.1"), |
392 | 246 | percent=if_else(percent!="0.0%", percent, "less than 0.1%")) |
393 | 247 | |
394 | 248 | |
395 | 249 | |
396 | 250 | |
397 | -top5 <- cases %>% | |
398 | - group_by(case_no) %>% | |
251 | +## top5 <- cases %>% | |
252 | +## group_by(case_no) %>% | |
253 | +## summarise(expenditure=sum(amount_spent_aid_element_in_eur_million)) %>% | |
254 | +## ungroup %>% | |
255 | +## arrange(desc(expenditure)) %>% | |
256 | +## mutate(share=expenditure/sum(expenditure)) %>% | |
257 | +## slice(1:5) %>% | |
258 | +## mutate(cum_share=cumsum(share), | |
259 | +## cum_expenditure=cumsum(expenditure)) %>% | |
260 | +## filter(expenditure>0) | |
261 | + | |
262 | + | |
263 | +top5 <- scoreboard_ms |> | |
264 | + filter(year==max(year)) |> | |
265 | + group_by(case_no) |> | |
399 | 266 | summarise(expenditure=sum(amount_spent_aid_element_in_eur_million)) %>% |
400 | - ungroup %>% | |
401 | - arrange(desc(expenditure)) %>% | |
402 | - mutate(share=expenditure/sum(expenditure)) %>% | |
403 | - slice(1:5) %>% | |
267 | + ungroup() |> | |
268 | + arrange(desc(expenditure)) |> | |
269 | + mutate(share=expenditure/sum(expenditure)) |> | |
270 | + slice(1:5) |> | |
404 | 271 | mutate(cum_share=cumsum(share), |
405 | - cum_expenditure=cumsum(expenditure)) %>% | |
272 | + cum_expenditure=cumsum(expenditure)) |> | |
406 | 273 | filter(expenditure>0) |
407 | 274 | |
408 | 275 | |
409 | -top5_share <- top5 %>% | |
410 | - pull(cum_share) %>% | |
411 | - max() %>% | |
412 | - "*"(100) %>% | |
276 | + | |
277 | + | |
278 | +top5_share <- top5 |> | |
279 | + pull(cum_share) |> | |
280 | + max() |> | |
281 | + multiply_by(100) |> | |
413 | 282 | round(1) |
414 | 283 | |
415 | 284 | |
416 | -top5_expenditure <- top5 %>% | |
417 | - pull(cum_expenditure) %>% | |
285 | +top5_expenditure <- top5 |> | |
286 | + pull(cum_expenditure) |> | |
418 | 287 | max() |
419 | 288 | |
420 | 289 | |
421 | 290 | |
422 | 291 | |
423 | -total_expenditure <- scoreboard_ms %>% | |
424 | - filter(year>=ini_focus) %>% | |
425 | - pull(amount_spent_aid_element_in_eur_million) %>% | |
426 | - sum(na.rm=T) %>% "/"(1e3) %>% | |
292 | +total_expenditure <- scoreboard_ms |> | |
293 | + filter(year>=ini_focus) |> | |
294 | + pull(amount_spent_aid_element_in_eur_million) |> | |
295 | + sum(na.rm=T) |> divide_by(1e3) |> | |
427 | 296 | round(1) |
428 | 297 | |
429 | -total_expenditure_last <- scoreboard_ms %>% | |
430 | - filter(year==year_focus) %>% | |
431 | - pull(amount_spent_aid_element_in_eur_million) %>% | |
432 | - sum(na.rm=T) %>% "/"(1e3) %>% | |
298 | +total_expenditure_last <- scoreboard_ms |> | |
299 | + filter(year==year_focus) |> | |
300 | + pull(amount_spent_aid_element_in_eur_million) |> | |
301 | + sum(na.rm=T) |> divide_by(1e3) |> | |
433 | 302 | round(2) |
434 | 303 | |
435 | 304 | |
436 | -cofinancing <- scoreboard_ms %>% | |
305 | +cofinancing <- scoreboard_ms |> | |
437 | 306 | filter( year==max(year), |
438 | 307 | ## duration_end>=max(year), |
439 | 308 | amount_spent_aid_element_in_eur_million>0 |
440 | - ) %>% | |
309 | + ) |> | |
441 | 310 | mutate(expenditure=amount_spent_aid_element_in_eur_million* |
442 | 311 | co_financed) |
443 | 312 |
@@ -445,9 +314,9 @@ | ||
445 | 314 | |
446 | 315 | |
447 | 316 | |
448 | -cofinancing_expenditure <- cofinancing %>% | |
449 | - pull(expenditure) %>% | |
450 | - sum %>% | |
317 | +cofinancing_expenditure <- cofinancing |> | |
318 | + pull(expenditure) |> | |
319 | + sum() |> | |
451 | 320 | round(0) |
452 | 321 | |
453 | 322 |
@@ -455,67 +324,67 @@ | ||
455 | 324 | *100,1) |
456 | 325 | |
457 | 326 | |
458 | -cofinancing_objective <- cofinancing %>% | |
459 | - group_by(scoreboard_objective) %>% | |
460 | - summarise(expenditure_objective=sum(expenditure)) %>% | |
461 | - ungroup %>% | |
462 | - arrange(desc(expenditure_objective)) %>% | |
463 | - mutate(share=expenditure_objective/sum(expenditure_objective)*100) %>% | |
327 | +cofinancing_objective <- cofinancing |> | |
328 | + group_by(scoreboard_objective) |> | |
329 | + summarise(expenditure_objective=sum(expenditure)) |> | |
330 | + ungroup() |> | |
331 | + arrange(desc(expenditure_objective)) |> | |
332 | + mutate(share=expenditure_objective/sum(expenditure_objective)*100) |> | |
464 | 333 | mutate(share=round_preserve_sum(share,1)) |
465 | 334 | |
466 | 335 | |
467 | 336 | |
468 | 337 | |
469 | -expenditure_by_objective <- scoreboard_ms %>% | |
338 | +expenditure_by_objective <- scoreboard_ms |> | |
470 | 339 | filter(year==max(year), |
471 | 340 | ## duration_end>=max(year), |
472 | 341 | amount_spent_aid_element_in_eur_million>0 |
473 | - )%>% | |
342 | + ) |> | |
474 | 343 | mutate(scoreboard_objective=recode(scoreboard_objective, |
475 | - "Other"="Other policy objectives" )) %>% | |
476 | - group_by(scoreboard_objective) %>% | |
477 | - summarise(expenditure_objective=sum(amount_spent_aid_element_in_eur_million)) %>% | |
478 | - ungroup %>% | |
479 | - arrange(desc(expenditure_objective)) %>% | |
480 | - mutate(objectives_reduced=if_else(scoreboard_objective %in% scoreboard_objective[1:4], scoreboard_objective, "Other policy objectives" )) %>% | |
481 | - group_by(objectives_reduced) %>% | |
482 | - summarise(expenditure2=sum(expenditure_objective)) %>% | |
483 | - ungroup %>% | |
484 | - arrange(desc(expenditure2)) %>% | |
485 | - mutate(share=expenditure2/sum(expenditure2)) %>% | |
486 | - mutate(share2=round_preserve_sum(share*100,1)) %>% | |
487 | - mutate(share_label=paste(as.character(share2), "%", sep="")) %>% | |
488 | - move_row(which(.$objectives_reduced=="Other policy objectives"), nrow(.)) %>% | |
344 | + "Other"="Other policy objectives" )) |> | |
345 | + group_by(scoreboard_objective) |> | |
346 | + summarise(expenditure_objective=sum(amount_spent_aid_element_in_eur_million)) |> | |
347 | + ungroup() |> | |
348 | + arrange(desc(expenditure_objective)) |> | |
349 | + mutate(objectives_reduced=if_else(scoreboard_objective %in% scoreboard_objective[1:4], scoreboard_objective, "Other policy objectives" )) |> | |
350 | + group_by(objectives_reduced) |> | |
351 | + summarise(expenditure2=sum(expenditure_objective)) |> | |
352 | + ungroup() |> | |
353 | + arrange(desc(expenditure2)) |> | |
354 | + mutate(share=expenditure2/sum(expenditure2)) |> | |
355 | + mutate(share2=round_preserve_sum(share*100,1)) |> | |
356 | + mutate(share_label=paste(as.character(share2), "%", sep="")) %>% | |
357 | + move_row(which(.$objectives_reduced=="Other policy objectives"), nrow(.)) |> | |
489 | 358 | ## mutate(objectives_reduced=wrapper1(objectives_reduced, 25)) %>% |
490 | - mutate(objectives_reduced=factor(objectives_reduced)) %>% | |
359 | + mutate(objectives_reduced=factor(objectives_reduced)) |> | |
491 | 360 | mutate(objectives_reduced=fct_inorder(objectives_reduced)) |
492 | 361 | |
493 | -expenditure_gber <- scoreboard_ms %>% | |
362 | +expenditure_gber <- scoreboard_ms |> | |
494 | 363 | filter(year==max(year), |
495 | 364 | ## duration_end>=max(year), |
496 | 365 | amount_spent_aid_element_in_eur_million>0 |
497 | - )%>% | |
498 | - filter(!is.na(all_objective_names_gber_only)) %>% | |
499 | - group_by(all_objective_names_gber_only) %>% | |
500 | - summarise(expenditure=sum(amount_spent_aid_element_in_eur_million)) %>% | |
501 | - ungroup %>% | |
502 | - arrange(desc(expenditure)) %>% | |
503 | - mutate(share=expenditure/sum(expenditure)) %>% | |
366 | + ) |> | |
367 | + filter(!is.na(all_objective_names_gber_only)) |> | |
368 | + group_by(all_objective_names_gber_only) |> | |
369 | + summarise(expenditure=sum(amount_spent_aid_element_in_eur_million)) |> | |
370 | + ungroup() |> | |
371 | + arrange(desc(expenditure)) |> | |
372 | + mutate(share=expenditure/sum(expenditure)) |> | |
504 | 373 | mutate(share2=round_preserve_sum(share*100,1)) |
505 | 374 | |
506 | 375 | |
507 | -expenditure_aid <- scoreboard_ms %>% | |
376 | +expenditure_aid <- scoreboard_ms |> | |
508 | 377 | filter(year==max(year), |
509 | 378 | ## duration_end>=max(year), |
510 | 379 | amount_spent_aid_element_in_eur_million>0 |
511 | - )%>% | |
512 | - filter(!is.na(harmonised_aid_instrument)) %>% | |
513 | - group_by(harmonised_aid_instrument) %>% | |
514 | - summarise(expenditure=sum(amount_spent_aid_element_in_eur_million)) %>% | |
515 | - ungroup %>% | |
516 | - arrange(desc(expenditure)) %>% | |
517 | - mutate(share=expenditure/sum(expenditure)) %>% | |
518 | - mutate(share2=round_preserve_sum(share*100,1)) %>% | |
380 | + ) |> | |
381 | + filter(!is.na(harmonised_aid_instrument)) |> | |
382 | + group_by(harmonised_aid_instrument) |> | |
383 | + summarise(expenditure=sum(amount_spent_aid_element_in_eur_million)) |> | |
384 | + ungroup() |> | |
385 | + arrange(desc(expenditure)) |> | |
386 | + mutate(share=expenditure/sum(expenditure)) |> | |
387 | + mutate(share2=round_preserve_sum(share*100,1)) |> | |
519 | 388 | mutate(expenditure2=round(expenditure,0)) |
520 | 389 | |
521 | 390 | ``` |