Learn R Programming

SportMiner (version 0.1.0)

sm_plot_topic_trends: Plot Topic Trends Over Time

Description

Creates a stacked percentage bar chart showing how topic proportions change over publication years.

Usage

sm_plot_topic_trends(
  model,
  dtm,
  metadata,
  doc_id_col = "doc_id",
  year_filter = NULL
)

Value

A ggplot object.

Arguments

model

A fitted topic model (LDA, STM, or CTM).

dtm

The document-term matrix used to train the model.

metadata

Data frame with a 'year' column and document identifiers.

doc_id_col

Name of the document ID column in metadata. Default is "doc_id".

year_filter

Optional vector of years to include. Default is NULL (includes all years).

Examples

Run this code
if (FALSE) {
# Requires trained model and metadata
papers$doc_id <- paste0("doc_", seq_len(nrow(papers)))
lda_model <- sm_train_lda(dtm, k = 10)
sm_plot_topic_trends(lda_model, dtm, metadata = papers)
}

Run the code above in your browser using DataLab