Synthèse des travaux des étudiants
Dans le cadre du cours d’Economie contemporaine, un travail sur la recherche et lecture d’un article d’actualité à été proposé.
Avec comme consigne de synthétiser l’article puis reformuler un titre et proposer une ou des questions de débat.
Code
library(readr)
library(dplyr)
library(stringr)
library(jsonlite)
library(tidytext)
library(ggplot2)
library(ggwordcloud)
library(stopwords)
# --- Lecture fichier ---
raw_lines <- readLines("questions_titres.csv", encoding = "Latin1")
raw_lines <- iconv(raw_lines, from = "Latin1", to = "UTF-8")
tmp_file <- tempfile(fileext = ".csv")
writeLines(raw_lines, tmp_file)
df <- read_csv(tmp_file, show_col_types = FALSE)
# --- Nettoyage ---
df <- df %>%
rename(Titre = Titre_simplifie) %>%
mutate(Titre = str_trim(Titre)) %>%
filter(!is.na(Titre), Titre != "") %>%
arrange(Titre)
# --- Injection JSON dans la page HTML ---
cat(sprintf("<script>const titres = %s;</script>",
toJSON(df, dataframe = "rows", pretty = TRUE)))Code
# --- Tokenisation ---
mots <- df %>% unnest_tokens(word, Titre)
stopwords_fr <- stopwords(language = "fr", source = "snowball")
stopwords_perso <- c("cest","plus","sans","faire","france","etre","peut","le","la")
mots_clean <- mots %>%
filter(
!word %in% stopwords_fr,
!word %in% stopwords_perso,
str_detect(word, "^[\\p{L}’']+$")
)
freq <- mots_clean %>%
count(word, sort = TRUE) %>%
slice_max(n, n = 50)
# --- Nuage de mots ---
set.seed(123)
print(
ggplot(freq, aes(
label = word,
size = n,
color = factor(sample(1:6, nrow(freq), replace = TRUE)),
angle = sample(c(0, 45, 90, -45), nrow(freq), replace = TRUE)
)) +
geom_text_wordcloud(area_corr = TRUE) +
scale_size(range = c(4, 15)) +
scale_color_manual(values = c("#1F77B4","#FF7F0E","#2CA02C","#D62728","#9467BD","#8C564B")) +
theme_minimal() +
theme(
axis.text = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank()
) +
ggtitle("Titres les plus fréquents")
)