-
Notifications
You must be signed in to change notification settings - Fork 4
/
charts.R
178 lines (160 loc) · 4.64 KB
/
charts.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#' Pie charts of projects by budget
#'
#' draw the chart by budget bucket
#'
#' @param table
#'
#' @return a highchart
#' @export
#'
#' @examples
#' plot_tranchebudget(table = table_panorama)
#'
plot_tranchebudget <- function(table) {
gb_tranche <- table %>%
dplyr::group_by(cout_estime_par_tranche) %>%
dplyr::summarise(
n = n()
)
gb_tranche <- gb_tranche[c(1,5,3,4,2,6), ]
gb_tranche$cout_estime_par_tranche[gb_tranche$cout_estime_par_tranche == "< 5M€"] <- "Inf 5M€"
hc_tranche <- highcharter::highchart() %>%
highcharter::hc_add_series_labels_values(
gb_tranche$cout_estime_par_tranche,
gb_tranche$n,
name = "Nombre de projets",
colorByPoint = TRUE,
type = "pie",
colors = palette_budget())
return(hc_tranche)
}
#' Bar chart by phase
#'
#' @param table a data frame
#'
#' @return a hichchart
#' @export
#'
#' @examples
#' plot_phase(table = table_panorama)
plot_phase <- function(table) {
gb_phase <- table %>%
dplyr::group_by(ministere_nom_complet, phase_du_projet_en_cours) %>%
dplyr::summarise(
n = n()
) %>%
dplyr::filter(is.na(phase_du_projet_en_cours) == FALSE) %>%
tidyr::spread(phase_du_projet_en_cours, n, fill = 0)
hc_phase <- highcharter::highchart() %>%
highcharter::hc_chart(type = "bar") %>%
highcharter::hc_xAxis(categories = gb_phase$ministere_nom_complet) %>%
#Ajout projets terminés
highcharter::hc_add_series(
name = "Terminé",
data = gb_phase$"Terminé",
color = palette_phase()[5]
) %>%
highcharter::hc_add_series(
name = "Déploiement",
data = gb_phase$"Déploiement",
color = palette_phase()[4]
) %>%
highcharter::hc_add_series(
name = "Expérimentation",
data = gb_phase$'Expérimentation',
color = palette_phase()[3]
) %>%
highcharter::hc_add_series(
name = "Conception / Réalisation",
data = gb_phase$'Conception / Réalisation',
color = palette_phase()[2]
) %>%
highcharter::hc_add_series(
name = "Cadrage",
data = gb_phase$'Cadrage',
color = palette_phase()[1]
) %>%
highcharter::hc_plotOptions(
series = list(stacking="normal")
) %>%
highcharter::hc_legend(reversed = TRUE)
return(hc_phase)
}
#' Bar chart by budget
#'
#' @param table a data frame
#'
#' @return a highchart
#' @export
#'
#' @examples
#' plot_budget(table = table_panorama)
plot_budget <- function(table) {
gb_budget <- table %>%
dplyr::group_by(ministere_nom_complet, cout_estime_par_tranche) %>%
dplyr::summarise(n = n()) %>%
tidyr::spread(cout_estime_par_tranche, n, fill = 0)
hc_budget <- highcharter::highchart() %>%
highcharter::hc_chart(type = "bar") %>%
highcharter::hc_xAxis(categories = gb_budget$ministere_nom_complet) %>%
highcharter::hc_add_series(
name = "plus de 100 M€",
data = gb_budget$'plus de 100 M€',
color = palette_budget()[6]
) %>%
highcharter::hc_add_series(
name = "entre 20 et 100 M€",
data = gb_budget$'entre 20 et 100 M€',
color = palette_budget()[5]
) %>%
highcharter::hc_add_series(
name = "entre 9 et 20 M€",
data = gb_budget$'entre 9 et 20 M€',
color = palette_budget()[4]
) %>%
highcharter::hc_add_series(
name = "entre 5 et 9 M€",
data = gb_budget$'entre 5 et 9 M€',
color = palette_budget()[3]
) %>%
highcharter::hc_add_series(
name = "moins de 5 M€",
data = gb_budget$'moins de 5M€',
color = palette_budget()[2]
) %>%
highcharter::hc_add_series(
name = "en cadrage",
data = gb_budget$'en cadrage',
color = palette_budget()[1]
) %>%
highcharter::hc_plotOptions(
series = list(stacking="normal")
) %>%
highcharter::hc_legend(reversed = TRUE)
return(hc_budget)
}
#' Bar chart by zone
#'
#' @param table a data frame
#'
#' @return a highchart
#' @export
#'
#' @examples
#' plot_zone(table = table_panorama)
plot_zone <- function(table) {
gb_zone <- table %>%
dplyr::group_by(zone_fonctionnelle) %>%
dplyr::summarise(n = n()) %>%
dplyr::filter(is.na(zone_fonctionnelle) == FALSE)
hc_zone <- highcharter::highchart() %>%
highcharter::hc_add_series(
name = "Nombre de projets",
data = gb_zone,
type = "bar",
mapping = highcharter::hcaes(x = zone_fonctionnelle, y = n)
) %>%
highcharter::hc_xAxis(categories = gb_zone$zone_fonctionnelle) %>%
highcharter::hc_legend(enabled = FALSE)
return(hc_zone)
}