category_highlight_tokens: Highlight tokens per category

Description Usage Arguments Value Examples

View source: R/tag_tokens.r

Description

This is a convenience wrapper for tag_tokens() that can be used if tokens need to be colored per category

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
category_highlight_tokens(
  tokens,
  category,
  labels = NULL,
  alpha = 0.4,
  class = NULL,
  colors = NULL,
  unfold = NULL,
  span_adjacent = F,
  doc_id = NULL
)

Arguments

tokens

A character vector of tokens

category

Either a factor, or a numeric vector with values representing category indices. If a numeric vector is used, labels must also be given

labels

A character vector with labels for the categories

alpha

Optionally, the alpha (transparency) can be specified, with 0 being fully transparent and 1 being fully colored. This can be a vector to specify a different alpha for each value.

class

Optionally, a character vector of the class to add to the span tags. If NA no class is added

colors

A character vector with color names for unique values of the value argument. Has to be the same length as unique(na.omit(category))

unfold

Either a character vector or a named list of vectors of the same length as tokens. If given, all tokens with a tag can be clicked on to unfold the given text. If a list of vectors is given, the values of the columns are concatenated with the column name. E.g. list(doc_id = 1, sentence = 1) will be [doc_id = 1, sentence = 2]. This only works if the tagged tokens are used in the html browser created with the create_browser function (as it relies on javascript).

span_adjacent

If TRUE, include adjacent tokens with identical attributes within the same tag

doc_id

If span_adjacent is TRUE, The document ids are required to ensure that tags do not span from one document to another.

Value

a character vector of color-tagged tokens

Examples

1
2
3
tokens = c('token_1','token_2','token_3','token_4')
category = c('a','a',NA,'b')
category_highlight_tokens(tokens, category)

tokenbrowser documentation built on Oct. 23, 2020, 6:54 p.m.