Skip to contents

This function creates a word cloud for each topic.

Usage

gen_topic_clouds(model_output, n = 50)

Arguments

model_output

The output from model_topics function

n

The number of top terms to include in the word cloud

Value

A list of ggplot objects, where each element represents a word cloud for a 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-06-29 03:55:12.12514 scrape_goodreads_reviews: Completed! All book reviews extracted
#> Scraping run time = 6.58869171142578
#> 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, shakespear, claudius, watch, know, princ, kill, world, –, seem, ophelia, scene, horatio, father, natur, new, king, origin, act, feel, gertrud, good, tragedi, god, may, human, man, hes, mind, reveng, wonder, mad, ghost, saintmar, laert, state, denmark, histori, idea, mean, uncl, everyth, old, enter, half, ill, reason, young 
#> 
#> Topic 2:  
#> jane, love, book, stori, time, charact, make, read, rochest, much, eyr, just, way, like, feel, novel, life, mani, will, beauti, even, woman, reader, think, women, first, ever, bront, man, everi, fact, great, say, bad, kind, littl, written, must, also, friend, write, year, differ, know, age, though, men, independ, away, actual 
#> 
#> Topic 3:  
#> one, book, katniss, like, game, can, read, think, just, peopl, get, see, ’s, thing, will, take, say, also, hunger, never, peeta, now, want, person, still, realli, way, world, even, live, district, show, know, someth, girl, give, look, without, make, plot, start, yet, first, ’m, two, chapter, charact, time, keep, death 
#> 

# 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
# }