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)

Arguments

data

A data frame or tibble containing a text column.

text

The text column to scan, supplied unquoted.

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.

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

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.

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 assuming independent annotations (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