topicsInText: Coloring the words of a text corresponding to topic...

Description Usage Arguments Value Examples

View source: R/topicsInText.R

Description

The function creates a HTML document with the words of texts colored depending on the topic allocation of each word.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
topicsInText(
  text,
  ldaID,
  id,
  ldaresult,
  label = NULL,
  vocab,
  wordOrder = c("both", "alphabetical", "topics", ""),
  colors = NULL,
  fixColors = FALSE,
  meta = NULL,
  originaltext = NULL,
  unclearTopicAssignment = TRUE,
  htmlreturn = FALSE
)

Arguments

text

The result of LDAprep

ldaID

List of IDs for text

id

ID of the article of interest

ldaresult

A result object from the standardLDA

label

Optional label for each topic

vocab

Character: Vector of vocab corresponding to the text object

wordOrder

Type of output: "alphabetical" prints the words of the article in alphabetical order, "topics" sorts by topic (biggest topic first) and "both" prints both versions. All other inputs will result to no output (this makes only sense in combination with originaltext.

colors

Character vector of colors. If the vector is shorter than the number of topics it will be completed by "black" entrys.

fixColors

Logical: If FALSE the first color will be used for the biggest topic and so on. If fixColors=TRUE the the color-entry corresponding to the position of the topic is choosen.

meta

Optional input for meta data. It will be printed in the header of the output.

originaltext

Optional a list of texts (the text list of the textmeta object) including the desired text. Listnames must be IDs. Necessary for output in original text

unclearTopicAssignment

Logical: If TRUE all words which are assigned to more than one topic will not be colored. Otherwise the words will be colored in order of topic apperance in the ldaresult.

htmlreturn

Logical: HTML output for tests

Value

A HTML document

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
data(politics)
poliClean <- cleanTexts(politics)
words10 <- makeWordlist(text=poliClean$text)
words10 <- words10$words[words10$wordtable > 10]
poliLDA <- LDAprep(text=poliClean$text, vocab=words10)
LDAresult <- LDAgen(documents=poliLDA, K=10, vocab=words10)
topicsInText(text=politics$text, ldaID=names(poliLDA), id="ID2756",
             ldaresult=LDAresult, vocab=words10)
## End(Not run)

tosca documentation built on Oct. 28, 2021, 5:07 p.m.