set.seed(100)
library("quanteda")
toks <- data_char_ukimmig2010 |>
tokens(remove_punct = TRUE) |>
tokens_tolower() |>
tokens_remove(pattern = stopwords("english"), padding = FALSE)
fcmat <- fcm(toks, context = "window", tri = FALSE)
feat <- colSums(fcmat) |>
sort(decreasing = TRUE) |>
head(30) |>
names()
fcm_select(fcmat, pattern = feat) |>
textplot_network(min_freq = 0.5)
fcm_select(fcmat, pattern = feat) |>
textplot_network(min_freq = 0.8)
fcm_select(fcmat, pattern = feat) |>
textplot_network(min_freq = 0.8, vertex_labelcolor = rep(c('gray40', NA), 15))
fcm_select(fcmat, pattern = feat) |>
textplot_network(vertex_labelsize = 10)
fcm_30 <- fcm_select(fcmat, pattern = feat)
textplot_network(fcm_30,
vertex_labelsize = Matrix::rowSums(fcm_30) / min(Matrix::rowSums(fcm_30)))
# Vector inputs to vertex_labelsize can be scaled if too small / large
textplot_network(fcm_30,
vertex_labelsize = 1.5 * Matrix::rowSums(fcm_30) /
min(Matrix::rowSums(fcm_30)))
# as.igraph
if (requireNamespace("igraph", quietly = TRUE)) {
txt <- c("a a a b b c", "a a c e", "a c e f g")
mat <- fcm(tokens(txt))
as.igraph(mat, min_freq = 1, omit_isolated = FALSE)
}
Run the code above in your browser using DataLab