from_to {textshape}R Documentation

Prepare Discourse Data for Network Plotting

Description

from_to - Add the next speaker as the from variable in a to/from network data structure. Assumes that the flow of discourse is coming from person A to person B, or at the very least the talk is taken up by person B. Works by taking the vector of speakers and shifting everything down one and then adding a closing element.

from_to_summarize - A wrapper for from_to.data.frame that adds a word.count column and then combines duplicate rows.

Usage

from_to(x, ...)

## Default S3 method:
from_to(x, final = "End", ...)

## S3 method for class 'character'
from_to(x, final = "End", ...)

## S3 method for class 'factor'
from_to(x, final = "End", ...)

## S3 method for class 'numeric'
from_to(x, final = "End", ...)

## S3 method for class 'data.frame'
from_to(x, from.var, final = "End", ...)

from_to_summarize(x, from.var, id.vars = NULL, text.var = TRUE, ...)

Arguments

x

A data form vector or data.frame.

final

The name of the closing element or node.

from.var

A character string naming the column to be considered the origin of the talk.

id.vars

The variables that correspond to the speaker or are attributes of the speaker (from variable).

text.var

The name of the text variable. If TRUE duration tries to detect the text column.

...

Ignored.

Value

Returns a vector (if given a vector) or an augmented data.table.

Examples

from_to(DATA, 'person')
from_to_summarize(DATA, 'person')
from_to_summarize(DATA, 'person', c('sex', 'adult'))
## Not run: 
if (!require("pacman")) install.packages("pacman"); library(pacman)
p_load(dplyr, geomnet, qdap, stringi, scales)
p_load_current_gh('trinker/textsahpe')

dat <- from_to_summarize(DATA, 'person', c('sex', 'adult')) %>%
    mutate(words = rescale(word.count, c(.5, 1.5)))

dat %>%
    ggplot(aes(from_id = from, to_id = to)) +
        geom_net(
            aes(linewidth = words),
            layout.alg = "fruchtermanreingold",
            directed = TRUE,
            labelon = TRUE,
            size = 1,
            labelcolour = 'black',
            ecolour = "grey70",
            arrowsize = 1,
            curvature = .1
        ) +
        theme_net() +
        xlim(c(-0.05, 1.05))

## End(Not run)

[Package textshape version 1.7.5 Index]