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
#> 2024-10-25 03:01:06.511547 scrape_goodreads_reviews: Completed! All book reviews extracted
#> Scraping run time = 8.06545329093933
#> Total books processed: 3

# Model topics
topic_results <- model_topics(reviews, num_topics = 3, num_terms = 50, english_only = TRUE)
#> Topic 1:  
#> hamlet, play, charact, fuck, know, make, shakespear, one, claudius, seem, year, scene, great, right, father, may, action, princ, thought, act, man, ophelia, young, mother, take, becom, mad, brother, friend, also, horatio, consid, come, yet, noth, question, made, old, didnt, gertrud, look, work, good, word, refer, watch, die, ghost, king, that 
#> 
#> Topic 2:  
#> book, like, read, katniss, one, just, can, game, will, think, peopl, get, way, ’s, see, also, want, make, thing, love, feel, say, realli, stori, hunger, peeta, never, first, now, still, take, world, littl, need, review, mani, live, give, person, start, girl, even, charact, end, though, district, better, much, ’m, time 
#> 
#> Topic 3:  
#> jane, love, time, rochest, stori, eyr, much, book, reader, away, woman, women, bront, life, fact, novel, school, read, natur, first, power, even, men, john, write, might, cours, man, matter, world, god, wife, independ, ever, reread, day, classic, age, home, word, alway, possibl, element, poor, everi, male, suppos, short, marriag, heroin 
#> 

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