This function creates a word cloud for each topic.
Examples
# \donttest{
# Create a temporary file with sample book IDs
temp_file <- tempfile(fileext = ".txt")
writeLines(c("1420", "2767052", "10210"), temp_file)
# Scrape reviews
reviews <- scrape_reviews(temp_file, num_reviews = 30, use_parallel = FALSE)
#> Total book IDs to process: 3
#> 2025-03-04 01:31:09.121206 scrape_goodreads_reviews: Completed! All book reviews extracted
#> Scraping run time = 9.16258382797241
#> Total books processed: 3
# Model topics
topic_results <- model_topics(reviews, num_topics = 3, num_terms = 50, english_only = TRUE)
#> Topic 1:
#> hamlet, play, fuck, claudius, shakespear, scene, great, princ, world, act, ophelia, horatio, origin, man, watch, gertrud, writer, seem, hes, one, state, natur, king, reveng, mean, saintmar, alon, didnt, hand, laert, denmark, piec, get, enter, ill, work, three, les, die, ghost, polonius, meant, mother, fine, let, year, behind, exeunt, follow, good
#>
#> Topic 2:
#> love, jane, book, stori, time, read, charact, much, make, say, like, think, rochest, mani, know, life, even, eyr, ever, way, feel, everi, novel, find, see, first, reader, end, one, beauti, want, bront, woman, women, word, new, differ, thing, emot, fact, man, look, friend, though, write, written, mind, human, tell, idea
#>
#> Topic 3:
#> book, just, katniss, one, can, game, peopl, will, get, like, read, ’s, take, also, hunger, peeta, never, now, think, world, review, still, come, district, need, realli, yet, give, way, two, girl, year, death, part, make, better, see, thing, start, show, back, chapter, want, plot, person, first, know, thought, keep, live
#>
# Generate word clouds for each topic
wordcloud_plots <- gen_topic_clouds(topic_results, n = 20)
# Display the word cloud for the first topic
if (interactive()) {
print(wordcloud_plots[[1]])
}
# Clean up: remove the temporary file
file.remove(temp_file)
#> [1] TRUE
# }