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-05-07 04:12:28.491106 scrape_goodreads_reviews: Completed! All book reviews extracted
#> Scraping run time = 7.22407484054565
#> Total books processed: 3

# Model topics
topic_results <- model_topics(reviews, num_topics = 3, num_terms = 50, english_only = TRUE)
#> Topic 1:  
#> book, like, just, katniss, think, read, will, can, game, get, one, peopl, also, ’s, know, make, take, hunger, peeta, way, now, thing, see, never, person, say, still, realli, time, charact, first, come, girl, littl, even, review, world, someth, live, yet, district, show, want, mani, death, two, ’m, work, start, good 
#> 
#> Topic 2:  
#> love, jane, hamlet, stori, time, one, play, much, feel, rochest, charact, fuck, read, eyr, make, say, novel, end, man, even, way, everi, reader, claudius, beauti, word, woman, bront, scene, fact, may, women, great, right, life, young, mani, find, write, want, alway, friend, –, actual, idea, away, see, age, differ, ophelia 
#> 
#> Topic 3:  
#> year, shakespear, watch, dont, world, god, reread, origin, day, mean, cant, good, classic, matter, hes, first, fair, dark, mind, wasnt, imagin, saintmar, hous, state, back, author, home, ill, half, that, languag, three, natur, happen, royal, les, second, new, fine, wit, serious, histori, just, compar, omg, big, tome, piec, everyth, act 
#> 

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