desc <- suppressWarnings(readLines("DESCRIPTION"))
regex <- "(^Version:\\s+)(\\d+\\.\\d+\\.\\d+)"
loc <- grep(regex, desc)
ver <- gsub(regex, "\\2", desc[loc])
verbadge <- sprintf('<a href="https://img.shields.io/badge/Version-%s-orange.svg"><img src="https://img.shields.io/badge/Version-%s-orange.svg" alt="Version"/></a></p>', ver, ver)
verbadge <- ''
````

```r
library(knitr)
knit_hooks$set(htmlcap = function(before, options, envir) {
  if(!before) {
    paste('<p class="caption"><b><em>',options$htmlcap,"</em></b></p>",sep="")
    }
    })

knitr::opts_knit$set(self.contained = TRUE, cache = FALSE)
knitr::opts_chunk$set(fig.path = "tools/figure/")

Build Status Coverage Status r verbadge

textplot is a suite of text plotting tools that enable the user to analyze text data via serveral common text plotting methods. Methods include lexical dispersion plots, word trees, speech networks, co-occurrence networks, speech Gantt charts, text hilighting, and word clouds.

Functions

Installation

To download the development version of textplot:

Download the zip ball or tar ball, decompress and run R CMD INSTALL on it, or use the pacman package to install the development version:

if (!require("pacman")) install.packages("pacman")
pacman::p_load_current_gh("trinker/textplot")

Examples

if (!require("pacman")) install.packages("pacman")
pacman::p_load(dplyr, magrittr, textplot)
pacman::p_load_current_gh('trinker/numform')

Lexical Dispersion

sam_i_am %>%
    lexical_dispersion(c(' not ', ' eat ', ' sam ', ' (sam|eat) ')) %>%
    plot()
pres_debates2012 %>%
    dplyr::filter(person %in% c('ROMNEY', 'OBAMA')) %$%
    lexical_dispersion(text.var = dialogue, term.list = wrds, 
        grouping.var = person, rm.var = time
    ) %>%
    plot() +
        ggplot2::scale_x_continuous(labels = numform::ff_denom())
pres_debates2012 %>%
    dplyr::filter(person %in% c('ROMNEY', 'OBAMA')) %$%
    lexical_dispersion(text.var = dialogue, term.list = wrds, 
        grouping.var = person, rm.var = time
    ) %>%
    plot(bg.color = "black", grouping.var = list(fam.aff, sex),
        color = "yellow", total.color = "white", horiz.color="grey20"
    ) +
        ggplot2::scale_x_continuous(labels = numform::ff_denom())

Word Trees

word_tree(sam_i_am, word = 'I') %>%
    plot()

word_tree(sam_i_am, word = 'do') %>%
    plot()

presidential_debates_2012 %>%
    dplyr::filter(person %in% c('ROMNEY', 'OBAMA')) %$%
    word_tree(
        text.var = dialogue, 
        word = 'america', 
        grouping.var = person
    ) %>%
    plot()

Speech Networks

Co-occurrence Networks

Speech Gantt Charts

Text Hilighting

hilighter_cols %>%
    view_cols()

Regular Expresion Terms

map1 <- list(
    `#FF69B4` = c('we(\'[a-z]+)?\\b'),
    `#7CFC00` = c('he(\'[a-z]+)?\\b'),
    yellow = 'you',
    gray70 = '\\bi(?=$|\\s)'
)

set.seed(10)
presidential_debates_2012 %>%
    dplyr::filter(person %in% c('ROMNEY', 'OBAMA')) %>%
    dplyr::group_by(person) %>%
    dplyr::sample_n(15) %$%
    hilight_term(dialogue, map1, list(person)) %>%
    plot()

Token Matching

map2 <- list(
    `#FF69B4` = c('talk', 'you'),
    `#7CFC00` = c('he', "he's"),
    orange = c('we\'re', 'we'),
    yellow = 'that',
    gray70 = c('.', '?', '!')
)


set.seed(10)
presidential_debates_2012 %>%
    dplyr::filter(person %in% c('ROMNEY', 'OBAMA')) %>%
    dplyr::group_by(person) %>%
    dplyr::sample_n(15) %$%
    hilight_token(dialogue, map2, list(person)) %>%
    plot()

Sentence Matching

map3 <- list(
    'think',
    c('he is', "he's", 'you(\'[vr]e)?\\b'),
    '\\bi\\b'
) %>%
    map_cols(rev(hilighter_cols))


set.seed(10)
presidential_debates_2012 %>%
    dplyr::filter(person %in% c('ROMNEY', 'OBAMA')) %>%
    dplyr::group_by(person) %>%
    dplyr::sample_n(15) %$%
    hilight_sentence(dialogue, map3, list(person)) %>%
    plot()

Word Clouds

Word Cloud

Heat Cloud

Term Frequencies Bar/Lolipop

Comparative Term Frequencies Lolipop

Contact

You are welcome to:
- submit suggestions and bug-reports at: https://github.com/trinker/textplot/issues
- send a pull request on: https://github.com/trinker/textplot
- compose a friendly e-mail to: tyler.rinker@gmail.com



trinker/textplot documentation built on May 29, 2019, 1:38 p.m.