Description Usage Arguments Value Note Author(s) See Also Examples
View source: R/textplot_scale1d.R
Plot the results of a fitted scaling model, from (e.g.) a predicted quanteda.textmodels::textmodel_wordscores model or a fitted quanteda.textmodels::textmodel_wordfish or quanteda.textmodels::textmodel_ca model. Either document or feature parameters may be plotted: an ideal point-style plot (estimated document position plus confidence interval on the x-axis, document labels on the y-axis) with optional renaming and sorting, or as a plot of estimated feature-level parameters (estimated feature positions on the x-axis, and a measure of relative frequency or influence on the y-axis, with feature names replacing plotting points with some being chosen by the user to be highlighted).
1 2 3 4 5 6 7 8 9 10 |
x |
the fitted or predicted scaling model object to be plotted |
margin |
|
doclabels |
a vector of names for document; if left NULL (the default), docnames will be used |
sort |
if |
groups |
either: a character vector containing the names of document
variables to be used for grouping; or a factor or object that can be
coerced into a factor equal in length or rows to the number of documents.
|
highlighted |
a vector of feature names to draw attention to in a
feature plot; only applies if |
alpha |
A number between 0 and 1 (default 0.5) representing the level of
alpha transparency used to overplot feature names in a feature plot; only
applies if |
highlighted_color |
colour for highlighted terms in |
a ggplot2 object
The groups
argument only applies when margin = "documents"
.
Kenneth Benoit, Stefan Müller, and Adam Obeng
quanteda.textmodels::textmodel_wordfish()
,
quanteda.textmodels::textmodel_wordscores()
,
quanteda.textmodels::textmodel_ca()
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 | library("quanteda")
data(data_corpus_irishbudget2010, package = "quanteda.textmodels")
dfmat <- dfm(data_corpus_irishbudget2010)
## wordscores
refscores <- c(rep(NA, 4), 1, -1, rep(NA, 8))
tmod1 <- quanteda.textmodels::textmodel_wordscores(dfmat, y = refscores, smooth = 1)
# plot estimated document positions
textplot_scale1d(predict(tmod1, se.fit = TRUE),
groups = docvars(data_corpus_irishbudget2010, "party"))
# plot estimated word positions
textplot_scale1d(tmod1, margin = "features",
highlighted = c("minister", "have", "our", "budget"))
## wordfish
tmod2 <- quanteda.textmodels::textmodel_wordfish(dfmat, dir = c(6,5))
# plot estimated document positions
textplot_scale1d(tmod2)
textplot_scale1d(tmod2, groups = docvars(data_corpus_irishbudget2010, "party"))
# plot estimated word positions
textplot_scale1d(tmod2, margin = "features",
highlighted = c("government", "global", "children",
"bank", "economy", "the", "citizenship",
"productivity", "deficit"))
## correspondence analysis
tmod3 <- quanteda.textmodels::textmodel_ca(dfmat)
# plot estimated document positions
textplot_scale1d(tmod3, margin = "documents",
groups = docvars(data_corpus_irishbudget2010, "party"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.