plot.ETM {topicmodels.etm}R Documentation

Plot functionality for an ETM object

Description

Convenience function allowing to plot

Usage

## S3 method for class 'ETM'
plot(
  x,
  type = c("loss", "topics"),
  which,
  top_n = 4,
  title = "ETM topics",
  subtitle = "",
  encircle = FALSE,
  points = FALSE,
  ...
)

Arguments

x

an object of class ETM

type

character string with the type of plot to generate: either 'loss' or 'topics'

which

an integer vector of topics to plot, used in case type = 'topics'. Defaults to all topics. See the example below.

top_n

passed on to summary.ETM in order to visualise the top_n most relevant words for each topic. Defaults to 4.

title

passed on to textplot_embedding_2d, used in case type = 'topics'

subtitle

passed on to textplot_embedding_2d, used in case type = 'topics'

encircle

passed on to textplot_embedding_2d, used in case type = 'topics'

points

passed on to textplot_embedding_2d, used in case type = 'topics'

...

arguments passed on to summary.ETM

Value

In case type is set to 'topics', maps the topic centers and most emitted words for each topic to 2D using summary.ETM and returns a ggplot object by calling textplot_embedding_2d.
For type 'loss', makes a base graphics plot and returns invisibly nothing.

See Also

ETM, summary.ETM, textplot_embedding_2d

Examples


library(torch)
library(topicmodels.etm)
path  <- system.file(package = "topicmodels.etm", "example", "example_etm.ckpt")
model <- torch_load(path)
plot(model, type = "loss")



library(torch)
library(topicmodels.etm)
library(textplot)
library(uwot)
library(ggrepel)
library(ggalt)
path  <- system.file(package = "topicmodels.etm", "example", "example_etm.ckpt")
model <- torch_load(path)
plt   <- plot(model, type = "topics", top_n = 7, which = c(1, 2, 14, 16, 18, 19),
              metric = "cosine", n_neighbors = 15, 
              fast_sgd = FALSE, n_threads = 2, verbose = TRUE,
              title = "ETM Topics example")
plt


[Package topicmodels.etm version 0.1.0 Index]