-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hubert.R
62 lines (55 loc) · 1.84 KB
/
test_hubert.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
files <- list.files(
"_SharedFolder_GlobalES/Dashboard/Canada/json_files",
full.names = TRUE
)
# Parse only non-empty files, handling errors gracefully
json_list <- lapply(files, function(file) {
tryCatch(
rjson::fromJSON(file = file),
error = function(e) NULL # Return NULL if parsing fails
)
})
unique_source_id_values <- unique(unlist(sapply(json_list, function(json) if (!is.null(json)) names(json$source_id) else NULL)))
unique_source_id_values <- unique_source_id_values[grepl("ces", unique_source_id_values)]
# Create a dataframe with the required structure
result <- do.call(rbind, lapply(unique_source_id_values, function(survey_name) {
data.frame(
variable = basename(files), # File names
ces = survey_name, # Survey name
cleaned = sapply(json_list, function(json) {
if (!is.null(json) && "source_id" %in% names(json) &&
survey_name %in% names(json$source_id) &&
"cleaned" %in% names(json$source_id[[survey_name]])) {
json$source_id[[survey_name]]$cleaned
} else {
NA
}
}),
stringsAsFactors = FALSE
)
}))
library(ggplot2)
library(dplyr)
# Convertir les données en format approprié pour ggplot2
result_long <- result %>%
mutate(
cleaned_color = case_when(
cleaned == 1 ~ "Cleaned",
cleaned == 0 ~ "À faire",
is.na(cleaned) ~ "NA"
)
)
# Créer le graphique
ggplot(result_long, aes(x = ces, y = variable, fill = cleaned_color)) +
geom_tile(color = "white") + # Ajoute des contours blancs pour les cases
scale_fill_manual(
values = c("Cleaned" = "lightgreen", "À faire" = "red", "NA" = "gray"),
name = "Cleaned"
) +
theme_minimal() +
labs(
x = "Année (CES)",
y = "Fichiers JSON",
title = "Statut des données 'Cleaned' par année et fichier"
) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))