Analyzing emoji use across global subreddits​
​By Sajal Shukla
Emoji use across social media sites and public platforms has become commonplace in our ever-expanding digital world. This project extracts data from posts and comments under the subreddits of the five most populous countries, analyzes the most commonly used emojis in each of these subreddits, and performs sentiment analysis on three of those emojis. "Face with tears of joy”(😂) , "rolling on the floor laughing" (🤣), and “folded hands" (🙏) were found to be some of the most consistently used emojis (appearing on each subreddit), though the former two were used to express differing sentiment across each subreddit.

Introduction

Emojis are widely popular methods of expressing otherwise difficult to convey emotion or tone through textual conversation. As online conversation has become increasingly a part of everyday life across the world, emoji use has also become standard. Computational analysis of data from social media sites and public platforms can provide valuable, quantifiable insight into current trends of communication methods. Specifically, extracting data from posts and comments on Reddit, a globally used social media site which serves as a public discussion forum on a variety of topics, can provide us with information on the communication trends and tendencies of diverse groups of people around the world. This project collects and analyzes data on emoji usage on the subreddits of the five most populous countries.

Trial and Error with Reddit Data Extraction

In order to analyze emoji use across different subreddits, we must extract the posts from each subreddit. Initially, several attempts were made to extract data through Wolfram Language’s built-in ServiceConnect function.
First, a connection to Reddit is made.
In[]:=
reddit = ServiceConnect["Reddit", SaveConnectionTrue];
The subredditdata[] function takes 100 posts from a particular subreddit and extracts their titles. Each entry in the dataset is converted to String format using Normal[].
In[]:=
subredditdata[subreddit_String]:=(​​posts=reddit["SubredditPosts","Subreddit"subreddit,"ShowThumbnails"True, MaxItems100];​​postsdata = posts["Posts"];​​titledata = postsdata[[All, "Title"]];​​stringtitledata=Normal[#]&/@titledata​​)
In[]:=
Iconize[subredditdata["USA"]]
Out[]=
Dataset[
]
After extracting the data, a function was built to count how many times a certain character appears within the posts of the subreddit.
StringMatchQ is used to test whether or not the character appears at all in the data, and then Count determines how many times it does. This is mapped across the entire dataset.
In[]:=
countemoji[emoji_]:=Count[StringMatchQ[#, ___~~emoji~~ ___]&/@stringtitledata, True]
In[]:=
countemoji["😂"]
Out[]=
0
At this point, however, I reached an issue. Since Reddit encodes emojis in UTF-16 and Wolfram Language encodes them in UTF-8, Wolfram Language cannot identify the emojis in this dataset because it does not understand them.

Data Collection and Emoji Popularity Analysis

After numerous methods of attempting to resolve this issue, including through trying to convert emojis in the dataset to their character codes in UTF-8 with ToCharacterCode and then back to their correct appearance with FromCharacterCode, were unsuccessful, I needed to find an alternative method of collecting data. I decided to directly extract text from the webpages of each of the subreddits I intended to collect data from. The vast majority of posts and comments were taken from threads that were less than a week old, had more than ten comments, and contained emojis. Import and TextCases were used to help with the process of identifying threads with emoji usage. Those specific comments and posts were then transferred to a spreadsheet, uploaded to Wolfram Cloud, and used for my analysis. Anywhere from approximately fifty to one-hundred posts were collected from each subreddit.
Data is gathered from specific subreddits, transferred to spreadsheets, and uploaded to the Cloud. An association is made correlating each country with the link to its corresponding subreddit's data.
In[]:=
dataAssoc = <|"USA""https://www.wolframcloud.com/obj/1eebcdab-d35e-4618-bfe2-3a9143473bb0",​​"Pakistan""https://www.wolframcloud.com/obj/a2a6909a-d3eb-4fc2-bcc3-5bcc2eb440b4", "China"-> ​​"https://www.wolframcloud.com/obj/529bec12-1d21-4e89-afbd-6e7a6b3282b5", "India"-> ​​"https://www.wolframcloud.com/obj/461bb7ec-4d83-4067-8bab-a7ce1f349f02", ​​"Indonesia"->"https://www.wolframcloud.com/obj/b15e6e8f-ce83-4ae7-b271-9b1c331d4170"|>;
The data is cleaned up using Flatten[] and by deleting cases of strings Wolfram Language wrongly interprets to be emojis. TextCases[] is then used to extract the remaining emojis from the data. Lastly, an association matching each emoji to the number of times it was used on the Subreddit is made.
In[]:=
subredditsData[country_String]:=(​​postText = Flatten[CloudImport[dataAssoc[country]]];​​editText = StringDelete[#, __~~"xp"~~__]&/@postText;​​emojiData = Flatten[TextCases[editText, "Emoticon"]];​​countEmoji = Counts[emojiData])
In[]:=
subredditsData["USA"]
Out[]=
🐃1,🍑1,🎻1,😎2,:)3,👍5,😟1,🤣6,😡1,🚀5,😂5,🤜1,😱1,😏1,🙄2,🤘1,🤔2,💕1,😊1,❤️4,😳2,💯1,😍1,😜1,😤1,🤨1,🙏1,:D1,:(1,😹1,🤡1

Graphing the Data

To properly visualize the results of the emoji popularity analysis, the output from subredditsData[] is plotted on a bar graph.
The graphData[] function creates a title for the graph, plots the number of times each emoji is used in a particular subreddit on the bar chart, and implements correct spacing between each of the x-axis labels, which becomes particularly important as we begin to look at large numbers of different emojis.
In[]:=
graphData[country_String]:=(​​plotLabel = Style[StringJoin["Emoji Usage in Subreddit of ", country], Black, FontFamily"GT America"];​​BarChart[subredditsData[country], PlotLabelplotLabel, ChartStyle -> RGBColor[0.59, 0.8, 0.96], ImageSize->Scaled[1], BarSpacing->0.5,​​ChartLabelsPlaced[Keys[countEmoji],Below]])
In[]:=
Manipulate[graphData[Country],{Country,{"USA","Pakistan","China","Indonesia","India"}},SaveDefinitions->True]
Out[]=
​
Country
USA
Pakistan
China
Indonesia
India
BarChart[Counts[TextCases[StringDelete[$Failed,__~~xp~~__],Emoticon]],PlotLabelEmoji Usage in Subreddit
of USA,ChartStyle
,ImageSizeScaled[1],BarSpacing0.5,ChartLabels
Placed[Keys[Counts[TextCases[StringDelete[$Failed,__~~xp~~__],Emoticon]]],Below]]
It can be seen above that emoji use across global subreddits is incredibly varying. The one trend that is seen amongst the subreddits of the United States, Pakistan, China, Indonesia, and India, however, are their high levels of usage of the "face with tears of joy" (😂) emoji and the "rolling on the floor laughing" (🤣) emoji.

Emoji Sentiment Analysis

To expand on my analysis of global emoji usage, I decided to do sentiment analysis on some of the most commonly used emojis that appear in each of the subreddits in the hopes that this could provide insight into whether or not emojis are used for expressing similar emotion in various areas of the world.
The emojisSentiment[] function retrieves the data collected from each of the subreddit posts, separates the text into lines, and extracts all lines that contain a particular emoji. Classify[] is then used to determine whether the sentiment of each line is positive, negative, or neutral. The results are graphed in a pie chart.
In[]:=
emojisSentiment[emoji_String, country_String]:= (​​subredditsData[country];​​splitLines = TextCases[postText, "Line"];​​emojiLines = DeleteCases[Flatten[TextCases[#, ___~~emoji~~___]&/@splitLines], {}];​​sentList = Classify["Sentiment", #]&/@emojiLines;​​sentAssoc = Counts[sentList];​​pcLabel = Style[StringJoin["'",emoji, "' Sentiment Analysis - ", "Subreddit of ", country], FontColor->"Black", FontFamily->"GT America"];​​PieChart[Values[sentAssoc], SectorOrigin{Automatic,1},PlotLabelpcLabel, ​​ChartStyle"Pastel", ChartLegends{"Positive","Negative","Neutral"}]​​)

Graphing the Data

Emojis that appeared most consistently across each subreddit are chosen for sentiment analysis. The following visualization allows us to choose which emoji and which subreddit we'd like to view the results of sentiment analysis on.
In[]:=
Manipulate[emojisSentiment[Emoji,Country],Emoji,"😂","🤣","🙏",{Country,{"USA","Pakistan","China","Indonesia","India"}},SaveDefinitions->True]
Out[]=
​
Emoji
😂
🤣
🙏
Country
USA
Pakistan
China
Indonesia
India
PieChartValuesCountsTextCasesClassifierFunction
Input type: Text
Classes: Positive,Neutral,Negative
[Flatten[$Failed],
AcceptanceThresholdAutomatic,AnomalyDetectorNone,BatchProcessingAutomatic,ClassPriors
Automatic,IndeterminateThresholdAutomatic,MissingValueSynthesisAutomatic,PerformanceGoal
Automatic,RandomSeeding1234,RecalibrationFunctionAutomatic,TargetDeviceCPU,
TieBreakerFunctionRandomChoice,UtilityFunctionAutomatic],
ClassifierFunction
Input type: Text
Classes: Positive,Neutral,Negative
___~~😂~~___,AcceptanceThreshold
Automatic,AnomalyDetectorNone,BatchProcessingAutomatic,ClassPriorsAutomatic,
IndeterminateThresholdAutomatic,MissingValueSynthesisAutomatic,PerformanceGoalAutomatic,
RandomSeeding1234,RecalibrationFunctionAutomatic,TargetDeviceCPU,TieBreakerFunction
RandomChoice,UtilityFunctionAutomatic,SectorOrigin{Automatic,1},PlotLabel'😂' Sentiment
Analysis - Subreddit of USA,ChartStylePastel,ChartLegends{Positive,Negative,Neutral}
Although the "folded hands" (🙏) emoji seems to correlate largely with positive sentiment in all countries' subreddits with the exception of Indonesia, both of the more evidently joyous emojis, 😂 and 🤣, demonstrate surprisingly scattered sentiment across the various subreddits.

Conclusion

Though trends were certainly spotted in this analysis of emoji use across global subreddits, each country's subreddit produced largely differing data. The high levels of usage of the “face with tears of joy” (😂) emoji and the “rolling on the floor laughing” (🤣) emoji in each subreddit might have indicated a common societal tendency to want to express joy, laughter, or generally positive sentiment often, yet the results of sentiment analysis demonstrates that their usage was likely not always positive. In some cases, particularly in the r/China subreddit for the "face with tears of joy" emoji and in both the r/China and r/Pakistan subreddits for the "rolling on the floor laughing" emoji, the emojis' usage was correlated significantly with negative sentiment. In the future, in order to improve upon this project, I hope to be able to gather data in substantially larger amounts - potentially a thousand posts from each subreddit - in order to see clearer and more accurate communication trends across these global platforms.

Acknowledgments

I'd like to sincerely thank my mentor, CJ Applebaum, for the immense help, guidance, and encouragement she provided to me while I worked on this project. Thank you, also, to all of my peers and instructors for making the Wolfram High School Summer Camp such an incredible experience!

References

United States Census Bureau. (2019). Current Population. Census.gov. https://www.census.gov/popclock/print.php?component=counter