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-09-03 16:15:45.295685 scrape_goodreads_reviews: Completed! All book reviews extracted
#> Scraping run time = 6.78074383735657
#> Total books processed: 3

# Model topics
topic_results <- model_topics(reviews, num_topics = 3, num_terms = 50, english_only = TRUE)
#> Topic 1:  
#> book, like, katniss, one, will, think, just, can, read, game, peopl, ’s, also, see, get, make, way, stori, first, never, mani, hunger, want, peeta, even, much, thing, time, now, say, still, live, love, take, ever, review, come, littl, charact, start, girl, person, thought, someth, ’m, world, district, show, realli, two 
#> 
#> Topic 2:  
#> jane, love, life, rochest, stori, eyr, time, reader, much, world, make, woman, women, bront, book, feel, beauti, word, though, natur, everi, say, novel, write, cours, men, right, marri, john, let, way, might, school, take, god, independ, differ, truli, wife, even, need, young, friend, point, classic, heart, first, eye, charlott, later 
#> 
#> Topic 3:  
#> hamlet, know, read, play, charact, one, fuck, year, seem, well, love, shakespear, claudius, plot, great, man, scene, work, find, good, reason, time, feel, realli, fact, –, princ, act, must, yes, probabl, end, get, right, idea, rather, away, ophelia, everi, real, just, look, age, chang, horatio, old, moment, mad, matter, die 
#> 

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