lexical_dispersion_plot: Lexical Dispersion Plot

Description Usage Arguments Value Note Examples

Description

Generate a lexical dispersion plot of terms.

Usage

1
2
3
4
5
6
lexical_dispersion_plot(text.var, term.list, grouping.var = NULL,
  rm.var = NULL, group.names, time.names, ignore.case = TRUE,
  color = "blue", bg.color = "grey90", horiz.color = "grey85",
  total.color = "black", symbol = "|", title = "Lexical Dispersion Plot",
  rev.factor = TRUE, wrap = "'", xlab = "Dialogue (Words)", ylab = NULL,
  size = 4, scales = "free", space = "free", plot = TRUE, ...)

Arguments

text.var

The text variable.

term.list

A vector of quoted terms or a named list of quoted terms. If the latter terms will be combined into a single unified theme named according to the list names. Note that terms within the vectors of the list cannot be duplicated.

grouping.var

The grouping variables. Default NULL generates one word list for all text. Also takes a single grouping variable or a list of 1 or more grouping variables.

rm.var

The repeated measures variables. Default NULL generates one facet for all text. Also takes a single repeated measures variable or a list of 1 or more grouping variables.

group.names

A vector of names that corresponds to group.var. Generally for internal use.

time.names

A vector of names that corresponds to rm.var. Generally for internal use.

ignore.case

logical. If TRUE matching will be done without regard to case.

color

The color of the word symbols.

bg.color

The background color.

horiz.color

The color of the horizontal tracking stripe. Use horiz.color = bg.color to eliminate.

total.color

The color to use for summary 'all' group. If NULL totals are dropped.

symbol

The word symbol. Default is "|".

title

Title of the plot

rev.factor

logical. If TRUE reverses the plot order of the factors.

wrap

a character to wrap around the words (enables the reader to visualize spaces). Default is "'", use "" to remove.

xlab

The x label.

ylab

The y label.

size

The size of the plotting symbol.

scales

Should scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y")

space

If "fixed", the default, all panels have the same size. If "free_y" their height will be proportional to the length of the y scale; if "free_x" their width will be proportional to the length of the x scale; or if "free" both height and width will vary.

plot

logical. If TRUE the plot will automatically plot. The user may wish to set to FALSE for use in knitr, sweave, etc. to add additional plot layers.

...

Ignored.

Value

Plots a dispersion plot and invisibly returns the ggplot2 object.

Note

The match.terms is character sensitive. Spacing is an important way to grab specific words and requires careful thought. Using "read" will find the words "bread", "read" "reading", and "ready". If you want to search for just the word "read" you'd supply a vector of c(" read ", " reads", " reading", " reader").

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
with(DATA2, lexical_dispersion_plot(state, c('talk', 'good', 'the', ' the ', ' the'),
    list(person, sex), day))

with(DATA2, lexical_dispersion_plot(state, c('talk', 'good', 'the', ' the ', ' the'),
    list(person, sex), day, color = "red", bg.color = "white"))
## Not run: 
if (!require("pacman")) install.packages("pacman"); library(pacman)
p_load(qdap)

term_match(raj$dialogue, c(" love ", "love", " night ", "night"))
lexical_dispersion_plot(raj$dialogue, c(" love ", "love", " night ", "night"))
lexical_dispersion_plot(raj$dialogue, c("love", "night"), rm.var = raj$act)
with(rajSPLIT , lexical_dispersion_plot(dialogue, c("love", "night"),
    grouping.var = list(fam.aff, sex), rm.var = act))

## With grouping variables
with(rajSPLIT , lexical_dispersion_plot(dialogue, c("love", "night"),
     grouping.var = sex, rm.var = act))

## Drop total with `total.color = NULL`
with(rajSPLIT , lexical_dispersion_plot(dialogue, c("love", "night"),
     grouping.var = sex, rm.var = act, total.color = NULL))

## Change color scheme
with(rajSPLIT, lexical_dispersion_plot(dialogue, c("love", "night"),
    bg.color = "black", grouping.var = list(fam.aff, sex),
    color = "yellow", total.color = "white", horiz.color="grey20"))

## Use `word_list`
## Presidential debates by all
wrds <- word_list(pres_debates2012$dialogue, stopwords = Top200Words)
wrds2 <- spaste(wrds[["rfswl"]][["all"]][, "WORD"])
wrds2 <- c(" governor romney ", wrds2[-c(3, 12)])
with(pres_debates2012 , lexical_dispersion_plot(dialogue, wrds2, , time))

## Presidential debates by person
dat <- pres_debates2012
dat <- dat[dat$person %in% qcv(ROMNEY, OBAMA), ]

wordlist <- c(" tax", " health", " rich ", "america", " truth",
    " money", "cost", " governnor", " president", " we ",
    " job", " i ", " you ", " because ", " our ", " years ")

with(dat, lexical_dispersion_plot(dialogue, wordlist, total.color = NULL,
    bg.color = "white", grouping.var = person, rm.var = time,
    color = "black", horiz.color="grey80"))

wordlist2 <- c(" i'd ", " i'll ", " i'm ", " i've ", " i ",
    " we'd ", " we'll ", " we're ", " we've ", " we ",
    " you'd ",  " you'll ", " you're ", " you've ", " you ", " your ",
    " he'd ", " he'll ", " he's ", " he ")

with(dat, lexical_dispersion_plot(dialogue, wordlist2,
    bg.color = "black", grouping.var = person, rm.var = time,
    color = "yellow", total.color = NULL, horiz.color="grey20"))

with(dat, lexical_dispersion_plot(dialogue, wordlist2,
    bg.color = "black", grouping.var = person, rm.var = time,
    color = "red", total.color = "white", horiz.color="grey20"))

## `match.terms` as a named list
wordlist3 <- list(
    I = c(" i'd ", " i'll ", " i'm ", " i've ", " i "),
    we = c(" we'd ", " we'll ", " we're ", " we've ", " we "),
    you = c(" you'd ",  " you'll ", " you're ", " you've ", " you ", " your "),
    he = c(" he'd ", " he'll ", " he's ", " he ")
)

with(dat, lexical_dispersion_plot(dialogue, wordlist3,
    bg.color = "grey60", grouping.var = person, rm.var = time,
    color = "blue", total.color = "grey40", horiz.color="grey20"))

colsplit2df(scores(with(dat, termco(dialogue, list(time, person), wordlist3))))

## Extras:
## Reverse facets

x <- with(pres_debates2012 , lexical_dispersion_plot(dialogue, wrds2, rm.var = time))

## function to reverse ggplot2 facets
rev_facet <- function(x) {
    names(x$facet)[1:2] <- names(x$facet)[2:1]
    print(x)
}

rev_facet(x)

## Discourse Markers: See...
## Schiffrin, D. (2001). Discourse markers: Language, meaning, and context.
##    In D. Schiffrin, D. Tannen, & H. E. Hamilton (Eds.), The handbook of
##    discourse analysis (pp. 54-75). Malden, MA: Blackwell Publishing.

discoure_markers <- list(
    response_cries = c(" oh ", " ah ", " aha ", " ouch ", " yuk "),
    back_channels = c(" uh-huh ", " uhuh ", " yeah "),
    summons = " hey ",
    justification = " because "
)

(markers <- with(pres_debates2012,
    termco(dialogue, list(person, time), discoure_markers)
))
plot(markers, high="red")

with(pres_debates2012,
    termco(dialogue, list(person, time), discoure_markers, elim.old = FALSE)
)

with(pres_debates2012,
    lexical_dispersion_plot(dialogue, discoure_markers, person, time)
)

## End(Not run)

trinker/lexr documentation built on May 31, 2019, 8:52 p.m.