• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Commit MetaInfo

修订版031d01690f5b533ae00d40ab7a14d01855e94dc0 (tree)
时间2022-09-16 23:27:16
作者Lorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

I added some extra visualisations based on the aggregate importance of some factors.

更改概述

差异

diff -r efcf65d56700 -r 031d01690f5b R-codes/shiny_scoreboard.R
--- a/R-codes/shiny_scoreboard.R Fri Sep 16 15:36:18 2022 +0200
+++ b/R-codes/shiny_scoreboard.R Fri Sep 16 16:27:16 2022 +0200
@@ -15,6 +15,18 @@
1515 library(stringr)
1616 library(viridis)
1717
18+
19+topK <- function(x,k, myname="other"){
20+ tbl <- tabulate(x)
21+ names(tbl) <- levels(x)
22+ x <- as.character(x)
23+ levelsToKeep <- names(tail(sort(tbl),k))
24+ x[!(x %in% levelsToKeep)] <- myname
25+ factor(x)
26+ }
27+
28+
29+
1830 remove_trailing_spaces <- function(string){
1931 str_replace(gsub("\\s+", " ", str_trim(string)), "B", "b")
2032
@@ -138,6 +150,8 @@
138150 ##################################################################
139151
140152
153+k_levels <- 4
154+
141155 df_sc_ini <- readRDS("scoreboard.RDS")
142156
143157 df_sc <- df_sc_ini |>
@@ -278,9 +292,33 @@
278292 conditionalPanel(condition = "input.type_aggregation == 'year_instrument' ",
279293 dt_output2("Data selection","table4") ),
280294
295+
296+
297+
298+
299+ conditionalPanel(condition =
300+ "input.type_aggregation == 'year_instrument' ",
301+ plotlyOutput("myplot3" )),
302+
303+
304+
305+
306+
307+
308+
309+
310+
281311 conditionalPanel(condition = "input.type_aggregation == 'year_objective' ",
282312 dt_output2("Data selection","table5") ),
283313
314+ conditionalPanel(condition = "input.type_aggregation == 'year_objective' ",
315+ plotlyOutput("myplot4") ),
316+
317+
318+
319+
320+
321+
284322 conditionalPanel(condition = "input.type_aggregation == 'year_casetype' ",
285323 dt_output2("Data selection","table3") ),
286324
@@ -409,34 +447,100 @@
409447
410448
411449
412- yearly_instrument_agg <- reactive({
450+ ## yearly_instrument_agg <- reactive({
451+
452+
453+ ## data_sel() |>
454+ ## group_by(expenditure_year,harmonised_aid_instrument ) |>
455+ ## summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
456+ ## ungroup() |>
457+ ## mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
458+ ## make_wide_with_total("expenditure_year", "exp_mio_eur") ## |>
459+ ## ## arrange(desc(`All years`))
460+
461+ ## })
462+
463+
464+ yearly_instrument_agg_long <- reactive({
413465
414466
415467 data_sel() |>
416468 group_by(expenditure_year,harmonised_aid_instrument ) |>
417469 summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
418470 ungroup() |>
419- mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
471+ mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2))
472+
473+ })
474+
475+
476+ yearly_instrument_agg_long_top <- reactive({
477+
478+ yearly_instrument_agg_long() |>
479+ mutate(harmonised_aid_instrument_top=fct_lump_n(harmonised_aid_instrument,k_levels, exp_mio_eur, "All Other Instruments"))
480+
481+ })
482+
483+
484+ yearly_instrument_agg <- reactive({
485+
486+ yearly_instrument_agg_long() |>
487+
420488 make_wide_with_total("expenditure_year", "exp_mio_eur") ## |>
421489 ## arrange(desc(`All years`))
422490
423491 })
424492
425493
426- yearly_objective_agg <- reactive({
494+
495+
496+ ## yearly_objective_agg <- reactive({
497+
498+
499+ ## data_sel() |>
500+ ## group_by(expenditure_year, harmonised_primary_obj ) |>
501+ ## summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
502+ ## ungroup() |>
503+ ## mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
504+ ## make_wide_with_total("expenditure_year", "exp_mio_eur") ## |>
505+ ## ## arrange(desc(`All years`))
506+
507+ ## })
508+
509+
510+
511+
512+ yearly_objective_agg_long <- reactive({
427513
428514
429515 data_sel() |>
430516 group_by(expenditure_year, harmonised_primary_obj ) |>
431517 summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
432518 ungroup() |>
433- mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
519+ mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2))
520+
521+ })
522+
523+ yearly_objective_agg_long_top <- reactive({
524+ yearly_objective_agg_long() |>
525+ mutate(harmonised_primary_obj_top=fct_lump_n(harmonised_primary_obj,k_levels, exp_mio_eur, "All Other Objectives"))
526+
527+ })
528+
529+
530+
531+ yearly_objective_agg <- reactive({
532+
533+ yearly_objective_agg_long() |>
434534 make_wide_with_total("expenditure_year", "exp_mio_eur") ## |>
435535 ## arrange(desc(`All years`))
436536
437537 })
438538
539+
439540
541+
542+
543+
440544 yearly_casenumber_agg <- reactive({
441545
442546
@@ -562,11 +666,78 @@
562666
563667
564668
669+ myplot3 <- reactive({
670+
671+
672+
673+ n_colors <- yearly_instrument_agg_long_top() |>
674+ pull(harmonised_aid_instrument_top) |>
675+ unique() |>
676+ length()
677+
678+ fig <- plot_ly(yearly_instrument_agg_long_top(),
679+ x = ~expenditure_year, y = ~exp_mio_eur,
680+ type = 'bar', color = ~harmonised_aid_instrument_top,
681+ ## symbol = ~anno,
682+ colors = viridis_pal(option = "H")(n_colors)) %>%
683+ layout(hovermode = "x unified",xaxis = list(title="",
684+ tickformat="%d %b"),
685+ yaxis = list(title = 'Scoreboard Expenditure (Mio \u20ac)'),
686+ font = t) |>
687+layout(legend = list(orientation = "h", # show entries horizontally
688+ xanchor = "center", # use center of legend as anchor
689+ x = 0.5, y=1.1)) # put legend in center of x-axis
690+
691+
692+
693+})
694+
695+
696+ output$myplot3 <- renderPlotly({
697+ myplot3()
698+
699+ })
565700
566701
567702
568703
569704
705+
706+ myplot4 <- reactive({
707+
708+
709+
710+ n_colors <- yearly_objective_agg_long_top() |>
711+ pull(harmonised_primary_obj_top) |>
712+ unique() |>
713+ length()
714+
715+ fig <- plot_ly(yearly_objective_agg_long_top(),
716+ x = ~expenditure_year, y = ~exp_mio_eur,
717+ type = 'bar', color = ~harmonised_primary_obj_top,
718+ ## symbol = ~anno,
719+ colors = viridis_pal(option = "H")(n_colors)) %>%
720+ layout(hovermode = "x unified",xaxis = list(title="",
721+ tickformat="%d %b"),
722+ yaxis = list(title = 'Scoreboard Expenditure (Mio \u20ac)'),
723+ font = t) |>
724+layout(legend = list(orientation = "h", # show entries horizontally
725+ xanchor = "center", # use center of legend as anchor
726+ x = 0.5, y=1.1)) # put legend in center of x-axis
727+
728+
729+
730+})
731+
732+
733+ output$myplot4 <- renderPlotly({
734+ myplot4()
735+
736+ })
737+
738+
739+
740+
570741
571742
572743 }