to_ldavis {Twitmo} | R Documentation |
Create interactive visualization with LDAvis
Description
Converts LDA topic model to LDAvis compatible json string and starts server.
May require servr
Package to run properly. For conversion of STM topic models use toLDAvis.
Usage
to_ldavis(fitted, corpus, doc_term)
Arguments
fitted |
Fitted LDA Model. Object of class LDA) |
corpus |
Document corpus. Object of class corpus) |
doc_term |
document term matrix (dtm). |
Details
Beware that to_ldavis
might fail if the corpus contains documents that consist ONLY of numbers,
emojis or punctuation e.g. do not contain a single character string. This is due to a limitation in the topicmodels
package
used for model fitting that does not consider such terms as words and omits them causing the posterior to differ in length from the corpus.
If you encounter such an error, redo your pre-processing and exclude emojis, punctuation and numbers.
When using pool_tweets
you can remove emojis by specifying remove_emojis = TRUE
.
Value
Invisible Object (see serVis)).
See Also
Examples
## Not run:
library(Twitmo)
# load tweets (included in package)
mytweets <- load_tweets(system.file("extdata", "tweets_20191027-141233.json", package = "Twitmo"))
# Pool tweets into longer pseudo-documents
pool <- pool_tweets(data = mytweets)
pooled_dfm <- pool$document_term_matrix
pooled_corp <- pool$corpus
# fit your LDA model with 7 topics
model <- fit_lda(pooled_dfm, n_topics = 7, method = "Gibbs")
# Explore your topics with LDAvis
to_ldavis(model, pooled_corp, pooled_dfm)
## End(Not run)