# 5. СОЗДАНИЕ УЗЛОВ
nodes <- data.frame(
id = unique(c(artist_pairs$item1, artist_pairs$item2))
) |>
left_join(artist_freq, by = c("id" = "lemma"))
nodes <- nodes |>
mutate(
label = id,
image = case_when(
id == "Bernard" & file.exists(file.path(img_dir, "bernard.jpg")) ~
img_to_base64(file.path(img_dir, "bernard.jpg")),
id == "Breton" & file.exists(file.path(img_dir, "breton.jpg")) ~
img_to_base64(file.path(img_dir, "breton.jpg")),
id == "Cézanne" & file.exists(file.path(img_dir, "cezanne.jpg")) ~
img_to_base64(file.path(img_dir, "cezanne.jpg")),
id == "Corot" & file.exists(file.path(img_dir, "corot.jpg")) ~
img_to_base64(file.path(img_dir, "corot.jpg")),
id == "Courbet" & file.exists(file.path(img_dir, "courbet.jpeg")) ~
img_to_base64(file.path(img_dir, "courbet.jpeg")),
id == "Daubigny" & file.exists(file.path(img_dir, "daubigny.jpg")) ~
img_to_base64(file.path(img_dir, "daubigny.jpg")),
id == "Degas" & file.exists(file.path(img_dir, "degas.jpg")) ~
img_to_base64(file.path(img_dir, "degas.jpg")),
id == "Delacroix" & file.exists(file.path(img_dir, "delacroix.jpg")) ~
img_to_base64(file.path(img_dir, "delacroix.jpg")),
id == "Giotto" & file.exists(file.path(img_dir, "giotto.jpg")) ~
img_to_base64(file.path(img_dir, "giotto.jpg")),
id == "Hals" & file.exists(file.path(img_dir, "hals.jpg")) ~
img_to_base64(file.path(img_dir, "hals.jpg")),
id == "Lautrec" & file.exists(file.path(img_dir, "lautrec.jpg")) ~
img_to_base64(file.path(img_dir, "lautrec.jpg")),
id == "Mauve" & file.exists(file.path(img_dir, "mauve.jpg")) ~
img_to_base64(file.path(img_dir, "mauve.jpg")),
id == "Mesdag" & file.exists(file.path(img_dir, "mesdag.jpg")) ~
img_to_base64(file.path(img_dir, "mesdag.jpg")),
id == "Michelangelo" & file.exists(file.path(img_dir, "michelangelo.jpg")) ~
img_to_base64(file.path(img_dir, "michelangelo.jpg")),
id == "Pissarro" & file.exists(file.path(img_dir, "pissarro.jpg")) ~
img_to_base64(file.path(img_dir, "pissarro.jpg")),
id == "Renoir" & file.exists(file.path(img_dir, "renoir.jpg")) ~
img_to_base64(file.path(img_dir, "renoir.jpg")),
id == "Rousseau" & file.exists(file.path(img_dir, "russo.jpg")) ~
img_to_base64(file.path(img_dir, "russo.jpg")),
id == "Rubens" & file.exists(file.path(img_dir, "rubens.jpg")) ~
img_to_base64(file.path(img_dir, "rubens.jpg")),
id == "Seurat" & file.exists(file.path(img_dir, "serat.jpg")) ~
img_to_base64(file.path(img_dir, "serat.jpg")),
id == "Signac" & file.exists(file.path(img_dir, "sinyak.jpg")) ~
img_to_base64(file.path(img_dir, "sinyak.jpg")),
id == "Sisley" & file.exists(file.path(img_dir, "sisley.jpg")) ~
img_to_base64(file.path(img_dir, "sisley.jpg")),
id == "Weissenbruch" & file.exists(file.path(img_dir, "weissenbruch.jpg")) ~
img_to_base64(file.path(img_dir, "weissenbruch.jpg")),
id == "Gauguin" & file.exists(file.path(img_dir, "gauguin.jpg")) ~
img_to_base64(file.path(img_dir, "gauguin.jpg")),
id == "Rembrandt" & file.exists(file.path(img_dir, "rembrandt.jpg")) ~
img_to_base64(file.path(img_dir, "rembrandt.jpg")),
id == "Daumier" & file.exists(file.path(img_dir, "daumier.jpg")) ~
img_to_base64(file.path(img_dir, "daumier.jpg")),
id == "Monet" & file.exists(file.path(img_dir, "monet.jpg")) ~
img_to_base64(file.path(img_dir, "monet.jpg")),
id == "Millet" & file.exists(file.path(img_dir, "millet.jpg")) ~
img_to_base64(file.path(img_dir, "millet.jpg")),
TRUE ~ NA_character_
),
shape = ifelse(!is.na(image), "circularImage", "dot"),
size = 30,
borderWidth = 2,
title = paste0(
"<b>", id, "</b><br>",
"Упоминаний: ", total_mentions,
sapply(id, get_artist_quotes, mentions_data = artist_mentions, n_quotes = 1)
)
)
# 6. СОЗДАНИЕ РЕБЕР
edges <- artist_pairs |>
rename(from = item1, to = item2) |>
mutate(
width = n / 5,
title = paste0("Упомянуты вместе: ", n, " раз")
)
# 7. КЛАСТЕРИЗАЦИЯ
g <- graph_from_data_frame(edges, directed = FALSE, vertices = nodes)
communities <- cluster_louvain(g)
nodes$group <- membership(communities)[match(nodes$id, V(g)$name)]
nodes <- nodes |>
mutate(
group_label = case_when(
group == 1 ~ "Импрессионисты и постимпрессионисты",
group == 2 ~ "Старые мастера и теоретики цвета",
group == 3 ~ "Барбизонская школа и голландцы",
TRUE ~ paste("Группа", group)
)
)