Learn R Programming

BERTopic (version 0.1.0)

bertopic_visualize_hierarchical_documents: Visualize hierarchical documents and topics

Description

Wrapper around Python BERTopic.visualize_hierarchical_documents(). This function visualizes documents and their topics in 2D at different levels of a hierarchical topic structure.

Usage

bertopic_visualize_hierarchical_documents(
  model,
  docs,
  hierarchical_topics,
  topics = NULL,
  embeddings = NULL,
  reduced_embeddings = NULL,
  sample = NULL,
  hide_annotations = FALSE,
  hide_document_hover = TRUE,
  nr_levels = 10L,
  level_scale = c("linear", "log"),
  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.

docs

Character vector of documents used in fit / fit_transform.

hierarchical_topics

A data frame or Python object as returned by BERTopic.hierarchical_topics(docs, ...).

topics

Optional integer vector of topic IDs to visualize.

embeddings

Optional numeric matrix of document embeddings.

reduced_embeddings

Optional numeric matrix of 2D reduced embeddings.

sample

Optional numeric (0–1) or integer controlling subsampling of documents per topic (forwarded to Python).

hide_annotations

Logical; if TRUE, hide cluster labels in the plot.

hide_document_hover

Logical; if TRUE, hide document text on hover to speed up rendering.

nr_levels

Integer; number of hierarchy levels to display.

level_scale

Character, either "linear" or "log", controlling how hierarchy distances are scaled across levels.

custom_labels

Logical or character scalar controlling label behavior (forwarded to Python).

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.