library("quanteda")
toks <- data_corpus_inaugural |>
corpus_subset(Year > 1970) |>
tokens()
# compare multiple documents
textplot_xray(kwic(toks, pattern = "american"))
textplot_xray(kwic(toks, pattern = "american"), scale = "absolute")
# compare multiple terms across multiple documents
textplot_xray(kwic(toks, pattern = "america*"),
kwic(toks, pattern = "people"))
if (FALSE) {
# how to modify the ggplot with different options
library("ggplot2")
tplot <- textplot_xray(kwic(toks, pattern = "american"),
kwic(toks, pattern = "people"))
tplot + aes(color = keyword) + scale_color_manual(values = c('red', 'blue'))
# adjust the names of the document names
docnames(toks) <- apply(docvars(toks, c("Year", "President")), 1, paste, collapse = ", ")
textplot_xray(kwic(toks, pattern = "america*"),
kwic(toks, pattern = "people"))
}
Run the code above in your browser using DataLab