Learn R Programming

sentometrics (version 0.2)

plot.sentomeasures: Plot sentiment measures

Description

Straightforward plotting method that shows all sentiment measures from the provided sentomeasures object in one plot, or the average along one of the lexicons, features and time weighting dimensions. We suggest to make use of the select_measures function when you desire to plot only a subset of the sentiment measures.

Usage

# S3 method for sentomeasures
plot(x, group = "all", ...)

Arguments

x

a sentomeasures object created using sento_measures.

group

a value from c("lexicons", "features", "time", "all"). The first three choices display the average of all measures from the same group, in a different color. The choice "all" displays every single sentiment measure in a separate color, but this may look visually overwhelming very fast, and can be quite slow.

...

not used.

Value

Returns a simple ggplot object, which can be added onto (or to alter its default elements) by using the + operator (see examples). By default, a legend is positioned at the top if there are at maximum twelve line graphs plotted.

Examples

Run this code
# NOT RUN {
data("usnews")
data("lexicons")
data("valence")

# construct a sentomeasures object to start with
corpus <- sento_corpus(corpusdf = usnews)
corpusSample <- quanteda::corpus_sample(corpus, size = 500)
l <- setup_lexicons(lexicons[c("LM_eng")], valence[["valence_eng"]])
ctr <- ctr_agg(howTime = c("equal_weight", "linear"), by = "year", lag = 3)
sentomeasures <- sento_measures(corpusSample, l, ctr)

# plot sentiment measures
plot(sentomeasures)
plot(sentomeasures, group = "features")

# adjust appearance of plot
p <- plot(sentomeasures)
p <- p +
  ggthemes::theme_base() +
  scale_x_date(name = "month-year") +
  scale_y_continuous(name = "newName")
p

# }

Run the code above in your browser using DataLab