View source: R/textplot_scale1d.R
textplot_scale1d | R Documentation |
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).
textplot_scale1d(
x,
margin = c("documents", "features"),
doclabels = NULL,
sort = TRUE,
groups = NULL,
highlighted = NULL,
alpha = 0.7,
highlighted_color = "black"
)
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 |
grouping variable for sampling, equal in length to the number
of documents. This will be evaluated in the docvars data.frame, so that
docvars may be referred to by name without quoting. This also changes
previous behaviours for |
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()
library("quanteda")
if (require("quanteda.textmodels")) {
dfmat <- dfm(tokens(data_corpus_irishbudget2010))
## wordscores
refscores <- c(rep(NA, 4), 1, -1, rep(NA, 8))
tmod1 <- textmodel_wordscores(dfmat, y = refscores, smooth = 1)
# plot estimated document positions
textplot_scale1d(predict(tmod1, se.fit = TRUE),
groups = 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 = 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 <- 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.