Learn R Programming

BERTopic (version 0.1.0)

bertopic_visualize_distribution: Visualize topic probability distribution

Description

Wrapper around Python BERTopic.visualize_distribution(). This function takes a single document's topic probability vector (e.g., one row from probs) and returns an interactive Plotly figure as HTML or writes it to disk.

Usage

bertopic_visualize_distribution(
  model,
  probs,
  min_probability = NULL,
  custom_labels = FALSE,
  title = NULL,
  width = NULL,
  height = NULL,
  file = NULL
)

Value

If file is NULL, an htmltools::HTML object. Otherwise, the normalized file path is returned invisibly.

Arguments

model

A "bertopic_r" model.

probs

Numeric vector of topic probabilities for a single document.

min_probability

Optional numeric scalar. If provided, only probabilities greater than this value are visualized (forwarded to min_probability in Python).

custom_labels

Logical or character scalar. If logical, whether to use custom topic labels as set via set_topic_labels(). If character, selects labels from other aspects (e.g., "Aspect1").

title

Optional character plot title.

width, height

Optional integer figure width/height in pixels.

file

Optional HTML output path. If NULL, an htmltools::HTML object is returned.