plot the dispersion of key word(s)

Share:

Description

Plots a dispersion or "x-ray" plot of selected word pattern(s) across one or more texts. The format of the plot depends on the number of kwic class objects passed: if there is only one document, keywords are plotted one below the other. If there are multiple documents the documents are plotted one below the other, with keywords shown side-by-side. Given that this returns a ggplot object, you can modify the plot by adding ggplot layers (see example).

Usage

1
2
## S3 method for class 'kwic'
plot(..., scale = c("absolute", "relative"), sort = FALSE)

Arguments

...

any number of kwic class objects

scale

whether to scale the token index axis by absolute position of the token in the document or by relative position. Defaults are absolute for single document and relative for multiple documents.

sort

whether to sort the rows of a multiple document plot by document name

Value

plot.kwic returns a ggplot object

Author(s)

Adam Obeng

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
inaugCorpusPost70 <- subset(inaugCorpus, Year > 1970)
# compare multiple documents
plot(kwic(inaugCorpusPost70, "american"))
plot(kwic(inaugCorpusPost70, "american"), scale = "absolute")
# compare multiple terms across multiple documents
plot(kwic(inaugCorpusPost70, "america*"), kwic(inaugCorpusPost70, "people"))

# how to modify the ggplot with different options
library(ggplot2)
g <- plot(kwic(inaugCorpusPost70, "american"), kwic(inaugCorpusPost70, "people"))
g + aes(color = keyword) + scale_color_manual(values = c('red', 'blue'))

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.