## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "#>", message = FALSE, warning = FALSE) # igraph is only Suggested, so every chunk that needs it is gated on it and the # vignette still builds where it is missing. has_igraph <- requireNamespace("igraph", quietly = TRUE) ## ----setup-------------------------------------------------------------------- library(tidyEmoji) library(dplyr) posts <- read.csv(system.file("extdata", "ata_tweets.csv", package = "tidyEmoji"), stringsAsFactors = FALSE, encoding = "UTF-8") ## ----------------------------------------------------------------------------- edges <- posts %>% emoji_pairs(full_text) edges edges %>% count(n, name = "pairs") ## ----------------------------------------------------------------------------- weighted <- posts %>% emoji_pairs(full_text, measure = "dice") %>% filter(n >= 2) weighted ## ----eval = has_igraph-------------------------------------------------------- g <- igraph::graph_from_data_frame( weighted[, c("item1", "item2", "dice", "n")], directed = FALSE) igraph::vcount(g) igraph::ecount(g) igraph::components(g)$no ## ----eval = has_igraph-------------------------------------------------------- set.seed(2026) # Louvain breaks ties at random; fix them for a stable answer communities <- igraph::cluster_louvain(g, weights = igraph::E(g)$dice) split(igraph::V(g)$name, igraph::membership(communities)) ## ----eval = FALSE------------------------------------------------------------- # library(ggraph) # ggraph(g, layout = "fr") + # geom_edge_link(aes(width = dice), alpha = 0.4) + # geom_node_text(aes(label = name), size = 6) + # scale_edge_width(range = c(0.3, 2)) + # theme_void() ## ----eval = has_igraph-------------------------------------------------------- table(igraph::degree(g)) length(communities)