Skip to contents

Create a count of bigrams and Visualize it in a network

Usage

tm_count_ngrams(df, var, clean_text = TRUE, ngram = 2, ...)

tm_ngrams_plot(
  ngrams,
  size_text = 4,
  edge_width = 1,
  edge_color = "black",
  node_color = "green",
  max_ngrams = 25
)

Arguments

df

A dataframe object.

var

Variable name (character vector) to create the ngrams of.

clean_text

Cleans text if TRUE.

ngram

Either a bigram (2) or a trigram (3).

...

Further arguments passed to [tm_clean_text()].

ngrams

Result of [tm_count_ngrams()].

size_text

Size of the label text.

edge_width

Size of the edge.

edge_color

color of the edge.

node_color

color of the node.

max_ngrams

Max ngrams to show on pot.

Value

A data.frame with count for [tm_count_ngrams()] or a ggplot object for [tm_ngrams_plot()]

Examples

library(janeaustenr)
library(ggplot2)
library(dplyr)
df <-
  austen_books() %>%
  filter(book == "Sense & Sensibility")

ngram_count <- tm_count_ngrams(df = df, var = "text", ngram = 2, remove_stopwords = TRUE)

set.seed(2019)
tm_ngrams_plot(ngram_count, max_ngrams = 50)