Skip to contents

emoji_sentiment() adds the mean emoji sentiment of each row, based on the Emoji Sentiment Ranking lexicon (see emoji_sentiment_lexicon). Scores range from -1 (negative) through 0 (neutral) to +1 (positive). Rows that contain no emoji, or whose emoji are absent from the lexicon, receive NA.

Usage

emoji_sentiment(
  data,
  text,
  lexicon = "novak2015",
  se = FALSE,
  presentation = "emoji"
)

Arguments

data

A data frame or tibble containing a text column. Grouped data frames are accepted. The verbs that work a row at a time (adding columns, or keeping and expanding rows) carry the grouping through to their result, as dplyr::mutate() and dplyr::filter() do. The verbs that pool across rows – the counts, the co-occurrence edge lists, the time series – warn that they ignore the grouping and return one corpus-wide answer.

text

The text column to scan, supplied unquoted. Any atomic column is accepted and read as character, so a factor works and a numeric, Date or logical one simply contains no emoji. A list column – or a data-frame column – is refused rather than coerced, because coercing one deparses it and the emoji found would be in the code rather than in your data. What counts as an emoji is the same in every verb; see the Detection section of tidyEmoji for the one case that surprises people, code points that are emoji only when they carry U+FE0F.

lexicon

Lexicon to use. The default, "novak2015", uses the bundled emoji_sentiment_lexicon. A registered lexicon (see register_emoji_lexicon()) or a data frame can also be supplied; see emoji_score() for the generic scorer.

se

If TRUE, also return .emoji_sentiment_se, the standard error of the row's mean sentiment. Requires the bundled "novak2015" lexicon. Default FALSE.

presentation

Which code points count as emoji: "emoji" (the default) or "any".

  • "emoji" requires emoji presentation, so U+2764 U+FE0F is an emoji and the bare U+2764 is not. This is the default and it will stay the default: widening it would silently recount every corpus already analysed.

  • "any" also reads the text-presentation spellings Unicode lists for an emoji (the bare heart, U+263A, U+2714, a keycap without its selector), because several keyboards emit them. It never reads the copyright, registered and trade-mark signs (U+00A9, U+00AE, U+2122), which are typography far more often than they are emoji.

"any" only ever adds occurrences: everything "emoji" finds, it finds too, in the same place. emoji_coverage() reports how many it adds and how many of those a lexicon can score, which is the cost of the choice in one number. Every verb that counts, scores or rewrites the emoji in a text column takes this argument, so counts still agree across the package for whichever value you use. The flag verbs do not need it, since a flag has no text-presentation form.

Value

data, as a tibble, with added columns .emoji_n (the number of emoji in the row), .emoji_n_scored (the number of emoji that actually appear in the lexicon), and .emoji_sentiment (the mean sentiment of the scored emoji). With se = TRUE, also .emoji_sentiment_se.

Details

The lexicon covers about 19% of the distinct emoji tidyEmoji can detect, and nothing added to Unicode after 2015, so NA is a common and meaningful answer. .emoji_n_scored reports the shortfall per row: 0 means the row had emoji that the lexicon could not score, NA that it had none at all. See emoji_sentiment_lexicon for the figure and its denominator.

Detection is grapheme-aware. Some lexicon entries are stored as unqualified, text-presentation code points (notably the bare heart, U+2764, without the U+FE0F variation selector); those are not treated as emoji in your text, so they are neither counted nor scored. Supply the emoji-presentation (qualified) form and it resolves normally. See emoji_sentiment_lexicon for the full picture.

Language and culture

The scores are not language-neutral. The bundled sentiment lexicon was annotated on tweets in 13 European languages and the emotion lexicon on English ones, and emoji use differs measurably across languages (Cross-lingual Variations in Emoji Use, EMNLP 2024), so a glyph's score describes how those annotators read it. For text from another language community, register a lexicon built there (see register_emoji_lexicon()) and report emoji_coverage() beside the result.

Uncertainty

A glyph annotated eight times should not carry the same authority as one annotated eight thousand times, and the bundled lexicon keeps the annotation counts that say which is which. With se = TRUE the result gains .emoji_sentiment_se, the standard error of the row's mean: each glyph's score has a binomial-style standard error computed from its own counts, and those are propagated to the mean over the row's distinct glyphs, assuming independent annotations: sqrt(sum(w^2 * se^2)), where w is each glyph's share of the row's scored occurrences. A repeated glyph is the same estimate again rather than new evidence, so one emoji written three times has the standard error of one. With every glyph distinct this is sqrt(sum(se^2)) / n_scored. It needs the annotation counts, so it is available for the bundled "novak2015" lexicon only. See emoji_ambiguity() for the same counts read as disagreement.

References

Kralj Novak P, Smailovic J, Sluban B, Mozetic I (2015) Sentiment of Emojis. PLoS ONE 10(12): e0144296. doi:10.1371/journal.pone.0144296

See also

emoji_sentiment_lexicon for the underlying scores; emoji_score() for scoring against any lexicon; emoji_emotion() for discrete emotions; emoji_ambiguity() for annotator disagreement.

Examples

df <- data.frame(text = c("love it \U0001f60d", "awful \U0001f621", "meh"))
emoji_sentiment(df, text)
#> # A tibble: 3 × 4
#>   text       .emoji_n .emoji_n_scored .emoji_sentiment
#>   <chr>         <int>           <int>            <dbl>
#> 1 love it 😍        1               1            0.678
#> 2 awful 😡          1               1           -0.173
#> 3 meh               0              NA           NA    
emoji_sentiment(df, text, se = TRUE)
#> # A tibble: 3 × 5
#>   text       .emoji_n .emoji_n_scored .emoji_sentiment .emoji_sentiment_se
#>   <chr>         <int>           <int>            <dbl>               <dbl>
#> 1 love it 😍        1               1            0.678             0.00711
#> 2 awful 😡          1               1           -0.173             0.0338 
#> 3 meh               0              NA           NA                NA