gen_topic_clouds: Create word cloud for topics

View source: R/topic_visualization.R

gen_topic_cloudsR Documentation

Create word cloud for topics

Description

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


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

# Model topics
topic_results <- model_topics(reviews, num_topics = 3, num_terms = 50, english_only = TRUE)

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


Goodreader documentation built on Oct. 30, 2024, 9:11 a.m.