Project Title
The Airline Quality Rating (AQR) is the most comprehensive study of performance and quality of the largest airlines in the United States. The rating is a multifactor examination of the airlines based on mishandled baggage, consumer complaints, on-time performance and involuntary denied boardings. the data is collected on a monthly basis and the AQR score is provided annualy.
Social media are increasingly reflecting and influencing behavior of other complex systems.In the aviation sector, sentiment analysis can help aviation companies detect sentiment polarity and sentiment topics by making use of data and examining the reputation of airlines for the Airline Quality Rating (AQR).
In this project, I considered the leading US airliners (Delta, JetBlue and United Airlines) to demonstrate the effect of tweets on Airline Reputation. The approach for this project is to count the positive and negative words in each tweet and assign a sentiment score which will enable me to determine how positive or negative a tweet is. I intend to use a publically available dictionary of positive and negative tweets for this project.
Does twitter sentiment have effect on Airline Reputation?
Data containing hashtag Delta, JetBlue and United Airline was extracted from public tweets.The first task was to create a developer app and using the api key to scrape the tweets from the website.
As a frequent Delta flyer, I’m motivated to compare the effect of sentiments between Delta airline and other leading airlines in the industry and determine how sentiment impacts Delta’s customer service and reputation. Sentiment analysis enables firms to understand customer sentiments in relation to the services provided. These insights could be used to improve services by understanding consumers’ comments and feedback. I believe sentiment analysis can help the airline companies to improve the overall customer experience and enhance brand image/reputation.
Packages Required
library(twitteR) #for fetching the tweets
library(ROAuth) #for authenticating R
library(plyr)
##
## Attaching package: 'plyr'
## The following object is masked from 'package:twitteR':
##
## id
library(stringr)
library(ggplot2)
Extracting and Analyzing Tweets Setting Authorization to Extract Tweets
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "http://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"
api_key <- "3nCxrWFpUXZr69weyrj3tpsrB"
api_secret <- "XWb3EhQASeA9ZruApAj1cUZdqRzxZo3qBMxHCAFdHfeyOVV8Oh"
access_token <- "1193959453705613314-RJOJ7rFQRb9x2PYa72xTFG0pkQllPH"
access_token_secret <- "4Vd7R8WQ1S9mzKdr3pS4mWU4wsUIbWYhIWaXiQCv61Z0p"
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)
## [1] "Using direct authentication"
Test the authentication by getting some tweets with:
searchTwitter("Delta")
## [[1]]
## [1] "fluxfm_berlin: 06.12. 02:37 Uhr: Delta Spirit \"Bushwick Blues\""
##
## [[2]]
## [1] "p_delta_v: <U+732B><U+3068><U+305F><U+3051><U+306E><U+3053> https://t.co/aX3kiSmNZs"
##
## [[3]]
## [1] "Delta_keity: @akina729 <U+30AD><U+30C4><U+3059><U+304E><U+308B>.."
##
## [[4]]
## [1] "Delta: @BradleyPollock Hi, Brad. I'll definitely look into it for you. In order to do so, could you please follow and send… https://t.co/p12gZHVg4h"
##
## [[5]]
## [1] "cmdtedcr329gnb: RT @GDJoseCastilloG: #GNB | Guardias Nacionales adscritos a la Fuerza de Tarea Antidrogas 61 (@GNB_antidrogas1) y al CZGNB-61 de servicio e…"
##
## [[6]]
## [1] "SharonKPIX: RT @KPIXtv: The Delta Barber Shop in #Antioch remains open after a woman rammed her car into a barber and the shop after allegedly being up…"
##
## [[7]]
## [1] "HpsuvCarlos: RT @ViceSocialT: #EnVídeo | En el marco del Plan de ofensiva Comunal se hará la entrega de certificados en el Edo. Delta Amacuro a nuevos C…"
##
## [[8]]
## [1] "girls_gvhoops: Both 8th Grade A and B teams raise their records to 3-0 with wins over Delta Woods. Way to go girls!"
##
## [[9]]
## [1] "MSN_001X_delta: https://t.co/yzTP7gQVhu"
##
## [[10]]
## [1] "p_delta_v: <U+753B><U+50CF><U+30D5><U+30A9><U+30EB><U+30C0><U+3092><U+898B><U+3066><U+3044><U+305F><U+3089><U+53EF><U+611B><U+3044><U+306E><U+304C><U+3067><U+3066><U+304D><U+305F>"
##
## [[11]]
## [1] "gkilti: RT @DontDregMeBro: Overnight [18m, 52s] Delta\nThese people are sick\n[& Jeff didn't off himself]\nTStamps also >> Drop #'s\n[15] Coincidentall…"
##
## [[12]]
## [1] "TajAkmal: @laura_bey @Delta What’s that, a 4 hour flight or so... best of luck! https://t.co/Oox51fXCAA"
##
## [[13]]
## [1] "MadMadsen3: @prayingmedic @PlanetQAnon It was no accident that @POTUS used the US Army (Delta Force and Rangers) to take out Ba… https://t.co/jBsMyXMlxd"
##
## [[14]]
## [1] "KollelBudget: GREAT PRICE!!! Delta Trinsic Single-Handle Pull-Down Sprayer Kitchen Faucet Only $149.37 + Free Shipping (reg. $292… https://t.co/Yx2WgQTee1"
##
## [[15]]
## [1] "ClarekNickolas: RT @Sifill_LDF: That lady has been a civil rights atty for 35 yrs @KellyannePolls. When you were dreaming of becoming a political consultan…"
##
## [[16]]
## [1] "undef_obj: @richbuggy @born2code @ednergizer @JoeEmison @dabit3 That being said, there are still patterns as I mentioned earli… https://t.co/ykC36LMr05"
##
## [[17]]
## [1] "cgilson33: RT @Sifill_LDF: That lady has been a civil rights atty for 35 yrs @KellyannePolls. When you were dreaming of becoming a political consultan…"
##
## [[18]]
## [1] "kiusanboy: @delta_so <U+3046><U+304A><U+3002><U+3002><U+3002><U+0001F62D><U+0001F62D>"
##
## [[19]]
## [1] "data_fuku: RT @4LoveofStarTrek: <U+0001F596><U+0001F3FC> @StarTrek fans, name your:\nFavorite Series: Voyager\nFavorite Episode: Message in a Bottle\nFavorite Character: EMH\nF…"
##
## [[20]]
## [1] "gkilti: RT @DontDregMeBro: Overnight [89m, or 1h, 29m, 52s] Delta - 52s repeated day prior\nOurGuys, STRONG; @POTUS Trolls #GeauxVote: 1111\nTheirs,…"
##
## [[21]]
## [1] "natsuki_delta: <U+98F4><U+7D30><U+5DE5>2<U+500B><U+8FFD><U+52A0><U+3055><U+308C><U+308B><U+3093><U+304B>"
##
## [[22]]
## [1] "Ansgarmc: RT @mico_viejo: @eduardoenred @aspauzarazuri De los creadores de:\n\"al pueblo no se le escucha\" (Mesia),\n \"no importa la opinion de los oyen…"
##
## [[23]]
## [1] "gkilti: RT @DontDregMeBro: Overnight [1570m or 26h] Delta -WINNING\nMAGGIE repeat day prior, Haberman this time\nMIL the ONLY way\nTraitor SCHIFFTY\nJE…"
##
## [[24]]
## [1] "HollieJoyJoy: RT @Sifill_LDF: That lady has been a civil rights atty for 35 yrs @KellyannePolls. When you were dreaming of becoming a political consultan…"
##
## [[25]]
## [1] "akina729: @Delta_keity <U+3042><U+3068><U+9060><U+5F81><U+8CBB><U+0001F926><U+0001F3FB><U+200D><U+2642><U+FE0F>"
searchTwitter("JetBlue")
## [[1]]
## [1] "Atravelers_Lyfe: RT @nbcsnl: “Honk! Honk! JetBlue! Bye bye, Nana!” https://t.co/tzHVVVFk3j"
##
## [[2]]
## [1] "alexandereross: @JetBlue For what it is worth, @jetblue has an outstanding and helpful social media team that answers questions and… https://t.co/TTzIrd1oWo"
##
## [[3]]
## [1] "NanBoe: @JetBlue\n thanks for being a let down. Just trying to go to my son’s Air Force graduation that I had zero involvem… https://t.co/lX0GdkiTXv"
##
## [[4]]
## [1] "drplanespotters: RT @dougkempf: N946JL Airbus A321-231 operating as JetBlue B6619 landing KSAN runway 27 on 5 December 2019. The motto on the nose says, \"Th…"
##
## [[5]]
## [1] "JetBlue: @aldotarantini We're truly sorry for the uncomfortable situation on board. If the mess hasn't been fully addressed,… https://t.co/FEYnLUQykY"
##
## [[6]]
## [1] "streetsxbehind: RT @nbcsnl: “Honk! Honk! JetBlue! Bye bye, Nana!” https://t.co/tzHVVVFk3j"
##
## [[7]]
## [1] "TooCloseToTheTV: @nbcsnl Reading this... while on JetBlue."
##
## [[8]]
## [1] "AngelGH94: @JetBlue Please, don't go. :'("
##
## [[9]]
## [1] "PlaneSpotIsCool: RT @dougkempf: N946JL Airbus A321-231 operating as JetBlue B6619 landing KSAN runway 27 on 5 December 2019. The motto on the nose says, \"Th…"
##
## [[10]]
## [1] "Kennycooley4: @JetBlue JetBlue is one the better airlines at tia."
##
## [[11]]
## [1] "carolospr51: RT @nbcsnl: “Honk! Honk! JetBlue! Bye bye, Nana!” https://t.co/tzHVVVFk3j"
##
## [[12]]
## [1] "SPClairebear: RT @nbcsnl: “Honk! Honk! JetBlue! Bye bye, Nana!” https://t.co/tzHVVVFk3j"
##
## [[13]]
## [1] "jon_dustin: @jessgrondin @VictoriaBonney United is terrible, AA in same boat. We like JetBlue, but they are only SEASONAL to PWM! <U+0001F92C>"
##
## [[14]]
## [1] "CaptRogerVictor: @JetBlue wins Twitter for today. https://t.co/5M0qcx8v6V"
##
## [[15]]
## [1] "RobbWuddog: RT @nbcsnl: “Honk! Honk! JetBlue! Bye bye, Nana!” https://t.co/tzHVVVFk3j"
##
## [[16]]
## [1] "A_jacobs21: RT @nbcsnl: “Honk! Honk! JetBlue! Bye bye, Nana!” https://t.co/tzHVVVFk3j"
##
## [[17]]
## [1] "ceciliafloresb: RT @eluniversocom: Jetblue comienza vuelos directos Guayaquil-Nueva York. <U+25BA> https://t.co/DeOXkgnA1K https://t.co/34I0wRayeF"
##
## [[18]]
## [1] "MannyVP: @JetBlue is doing #socialmedia the right way! <U+0001F496><U+0001F496><U+0001F496> https://t.co/hwkdYsbVlm"
##
## [[19]]
## [1] "vikkie: RT @JetBlue: From the Big Apple to the Pearl of the Pacific. Now offering our first nonstop flight between JFK and Guayaquil, Ecuador. http…"
##
## [[20]]
## [1] "SweetCreatury: RT @nbcsnl: “Honk! Honk! JetBlue! Bye bye, Nana!” https://t.co/tzHVVVFk3j"
##
## [[21]]
## [1] "jc_mendoz: RT @eluniversocom: Jetblue comienza vuelos directos Guayaquil-Nueva York. <U+25BA> https://t.co/DeOXkgnA1K https://t.co/34I0wRayeF"
##
## [[22]]
## [1] "CallMeTajaMarie: AND THEY FLEW JETBLUE AND I LEFT THAT JOB FOR THIS ONE SO WHO’S THE REAL LOSER HERE #ME #IMTHELOSER"
##
## [[23]]
## [1] "aldotarantini: @JetBlue traveling with my 4 kids and wife. Flight is full. Vomit is dry from previous flight. Crew was already aw… https://t.co/zkpSSbElih"
##
## [[24]]
## [1] "James_MalRlds: RT @nbcsnl: “Honk! Honk! JetBlue! Bye bye, Nana!” https://t.co/tzHVVVFk3j"
##
## [[25]]
## [1] "DiggaBruckShot: @JetBlue Jet Blue always on that sassy shit <U+0001F923>"
searchTwitter("United")
## [[1]]
## [1] "JennyUwishuknew: RT @JoeBiden: Our president should be able to meet a simple test: understanding that Puerto Ricans are American citizens, and that they are…"
##
## [[2]]
## [1] "paigen96: RT @LSU: Twitter's No. 1 trending topic in the United States right now: #SECChampionship\n\n#GeauxTigers @LSUfootball https://t.co/VRD9WTmo7w"
##
## [[3]]
## [1] "scifisportsguy: RT @ChrisMurphyCT: Rudy Giuliani is in Ukraine today, meeting with Ukranian leaders on behalf of the President of the United States, repres…"
##
## [[4]]
## [1] "Yx8Baby: RT @UNITED_CINEMAS: #<U+30ED><U+30FC><U+30BD><U+30F3> #<U+30D7><U+30EC><U+30DF><U+30A2><U+30E0><U+30ED><U+30FC><U+30EB><U+30B1><U+30FC><U+30AD> <U+304C><U+305D><U+306E><U+5834><U+3067>1000<U+540D><U+69D8><U+306B><U+5F53><U+305F><U+308B><U+266A>\n\n<U+3010><U+53C2><U+52A0><U+65B9><U+6CD5><U+3011>\n<U+2460>@UNITED_CINEMAS <U+3092><U+30D5><U+30A9><U+30ED><U+30FC>\n<U+2461><U+3053><U+306E><U+6295><U+7A3F><U+3092>RT\n<U+2462><U+25BC><U+3053><U+3061><U+3089><U+3092><U+30AF><U+30EA><U+30C3><U+30AF><U+3059><U+308B><U+3068><U+62BD><U+9078><U+7D50><U+679C><U+304C><U+308F><U+304B><U+308B>!<U+25BC>\nhttps://t.co/sQiX3J…"
##
## [[5]]
## [1] "IsabelG41875073: @Camila_Cabello My name is Isabel Gallegos. I’m from the United States. I live in Utah. I’m currently going to coll… https://t.co/qawr0KIRSu"
##
## [[6]]
## [1] "LThetweets9: RT @GOPChairwoman: Democrat leaders have no clear vision for America besides trying to steal the 2020 election away from voters though thei…"
##
## [[7]]
## [1] "koutaZAP: RT @UNITED_CINEMAS: 3<U+20E3><U+5E74><U+9593><U+3067><U+632F><U+3063><U+305F><U+7537><U+306E><U+6570>6<U+20E3>0<U+20E3>0<U+20E3><U+4EBA><U+2757><U+FE0F>\n\n<U+6620><U+753B><U+300E>#<U+96A0><U+308C><U+30D3><U+30C3><U+30C1><U+3084><U+3063><U+3066><U+307E><U+3057><U+305F><U+3002><U+300F>\n<U+672C><U+65E5><U+3001>12/6(<U+91D1>)<U+516C><U+958B>!\n\n<U+0001F381><U+30B5><U+30A4><U+30F3><U+5165><U+308A><U+30D7><U+30EC><U+30B9><U+3084><U+30AA><U+30EA><U+30B8><U+30CA><U+30EB><U+30C8><U+30FC><U+30C8><U+30D0><U+30C3><U+30B0><U+306A><U+3069><U+304C><U+5408><U+8A08>6<U+20E3><U+540D><U+69D8><U+306B><U+5F53><U+305F><U+308B>!\n https://t.co/y4VSD2fXIl\n\n><U+5FDC>…"
##
## [[8]]
## [1] "SchuckWHIG: RT @KyleH_DA: Halftime: United Township 24, Quincy 21. 15 first half turnovers are really making the difference for the Blue Devils, who ha…"
##
## [[9]]
## [1] "pDJBfq4SMtOiWJM: RT @NamneungBNK48TH: <U+0E41><U+0E1B><U+0E4A><U+0E14><U+0E14><U+0E14><U+0E41><U+0E1B><U+0E4A><U+0E14><U+0E14><U+0E14><U+0E14><U+0E14> L A N E 8 <U+2764><U+FE0F> \n<U+0E21><U+0E32><U+0E41><U+0E25><U+0E49><U+0E27><U+0E08><U+0E49><U+0E32><U+0E32><U+0E32><U+0E32> <U+0001F43B>\n\n<U+0E27><U+0E31><U+0E19><U+0E40><U+0E2A><U+0E32><U+0E23><U+0E4C> <U+0E17><U+0E35><U+0E48> 7 <U+0E18><U+0E35><U+0E21>\n<U+0E40><U+0E2A><U+0E37><U+0E49><U+0E2D> Milinland Neverdies\n<U+0E40><U+0E2A><U+0E37><U+0E49><U+0E2D><U+0E27><U+0E34><U+0E48><U+0E07> Runtogetherwit…"
##
## [[10]]
## [1] "_cc1cabello: RT @chartcamila: iTunes United Arab Emirates:\n\n#1. Romance (NEW)\n\n*14th #1 on iTunes*\n\nhttps://t.co/WqTHWcWGf9"
##
## [[11]]
## [1] "1KarinKeller: RT @ChrisMurphyCT: Rudy Giuliani is in Ukraine today, meeting with Ukranian leaders on behalf of the President of the United States, repres…"
##
## [[12]]
## [1] "AmazonianGal127: RT @WhipClyburn: If these activities are not impeachable, then we ought to amend the Constitution of the United States & get rid of impeach…"
##
## [[13]]
## [1] "moadeul: RT @TXTChartData: DAILY YOUTUBE VIDEO VIEWS BY COUNTRY AND CITY \n\n#1 South Korea ~310,989\n#2 United States ~198,486\n#3 Indonesia ~179,454…"
##
## [[14]]
## [1] "bnbeats: @chargergirl78 @MagnusPooh @trump_sucks_01 @RyanAFournier @realDonaldTrump Yes. Like the sunlight cleansing evidenc… https://t.co/PPueDikkqT"
##
## [[15]]
## [1] "girioficial1: RT @LeilaChujfi: United Fruits Compañy hoy Chiquita Brands y Dole. Bastante implicadas en delitos de lesa humanidad. No solo la CPI la está…"
##
## [[16]]
## [1] "carolinagurl817: RT @ARmastrangelo: Nancy Pelosi is not a “boss,” she is a PUBLIC SERVANT.\n\nIn the United States of America, government is SUBORDINATE to th…"
##
## [[17]]
## [1] "MattBlaze51: RT @AngrierWHStaff: Trump made a complete ass of himself — and the United States — on the world stage today, again refusing to commit to up…"
##
## [[18]]
## [1] "Rose56745469: RT @RepAndyBiggsAZ: It is a sad state in the United States Congress where one member – the chairman of the committee – starts spying and tr…"
##
## [[19]]
## [1] "razifrzak: RT @utdxtra: Ole: \"He's almost undroppable at the moment. He's so professional, he's not tainted by any superstar or fame, he just wants to…"
##
## [[20]]
## [1] "SaysSheToday: RT @AndriyUkraineTe: With America’s Mayor @RudyGiuliani prepping for tomorrow another hard working day in meetings with Mr. Shokin and Mr.…"
##
## [[21]]
## [1] "aboutmykoo: RT @TXTChartData: DAILY YOUTUBE VIDEO VIEWS BY COUNTRY AND CITY \n\n#1 South Korea ~310,989\n#2 United States ~198,486\n#3 Indonesia ~179,454…"
##
## [[22]]
## [1] "keiba_teioh_DS: RT @UNITED_CINEMAS: 3<U+20E3><U+5E74><U+9593><U+3067><U+632F><U+3063><U+305F><U+7537><U+306E><U+6570>6<U+20E3>0<U+20E3>0<U+20E3><U+4EBA><U+2757><U+FE0F>\n\n<U+6620><U+753B><U+300E>#<U+96A0><U+308C><U+30D3><U+30C3><U+30C1><U+3084><U+3063><U+3066><U+307E><U+3057><U+305F><U+3002><U+300F>\n<U+672C><U+65E5><U+3001>12/6(<U+91D1>)<U+516C><U+958B>!\n\n<U+0001F381><U+30B5><U+30A4><U+30F3><U+5165><U+308A><U+30D7><U+30EC><U+30B9><U+3084><U+30AA><U+30EA><U+30B8><U+30CA><U+30EB><U+30C8><U+30FC><U+30C8><U+30D0><U+30C3><U+30B0><U+306A><U+3069><U+304C><U+5408><U+8A08>6<U+20E3><U+540D><U+69D8><U+306B><U+5F53><U+305F><U+308B>!\n https://t.co/y4VSD2fXIl\n\n><U+5FDC>…"
##
## [[23]]
## [1] "suaverdez: RT @MrsWifeylyfe: Great experience to hear from our next President of the United States!!! #YangGang #YangGang2020 \n@AndrewYang He said he…"
##
## [[24]]
## [1] "shunin641: RT @UNITED_CINEMAS: <U+300E>#<U+30B8><U+30E5><U+30DE><U+30F3><U+30B8>/<U+30CD><U+30AF><U+30C8>·<U+30EC><U+30D9><U+30EB><U+300F>12/13(<U+91D1>)<U+516C><U+958B>\n<U+30D7><U+30EC><U+30BC><U+30F3><U+30C8><U+4F01><U+753B><U+7B2C>2<U+5F3E>!\n\n<U+4ECA><U+5EA6><U+306E> <U+30B8><U+30E5><U+30DE><U+30F3><U+30B8><U+306F><U+65B0><U+30B9><U+30C6><U+30FC><U+30B8><U+8FFD><U+52A0><U+3067><U+96E3><U+6613><U+5EA6><U+30A2><U+30C3><U+30D7>!\n<U+30B5><U+30D0><U+30A4><U+30D0><U+30EB><U+88C5><U+5099><U+3067><U+5168><U+30AF><U+30EA><U+3092><U+76EE><U+6307><U+305B>!\n“<U+30B8><U+30E5><U+30DE><U+30F3><U+30B8>”<U+30D5><U+30A1><U+30C3><U+30B7><U+30E7><U+30F3><U+30BB><U+30C3><U+30C8><U+304C>2<U+540D><U+69D8><U+306B><U+5F53><U+305F><U+308B>!\nhttps://t.…"
##
## [[25]]
## [1] "cheqlani: RT @tiyadofpolitics: Norway gifts the United Kingdom a Christmas tree every year to say thank you for supporting them in defeating Nazism 7…"
Import the downloaded dictionary of Positive and Negative words from the .txt file in my GitHub
posText <- readLines('https://raw.githubusercontent.com/Emahayz/Data-607-Class/master/positive-words.txt')
posText <- unlist(lapply(posText, function(x) { str_split(x, "\n") }))
negText <- readLines('https://raw.githubusercontent.com/Emahayz/Data-607-Class/master/negative-words.txt')
negText <- unlist(lapply(negText, function(x) { str_split(x, "\n") }))
pos.words = c(posText, 'upgrade')
neg.words = c(negText, 'wtf', 'wait', 'waiting','epicfail', 'mechanical')
Extract Tweets with Hashtags relating to Delta, JetBlue and United Airlines
delta_tweets = searchTwitter('@delta', n=2000)
jetblue_tweets = searchTwitter('@jetblue', n=2000)
united_tweets = searchTwitter('@united', n=2000)
Processing Tweets
delta_txt = sapply(delta_tweets, function(t) t$getText() )
jetblue_txt = sapply(jetblue_tweets, function(t) t$getText() )
united_txt = sapply(united_tweets, function(t) t$getText() )
Calculate the number of tweets for each airline.
noof_tweets = c(length(delta_txt), length(jetblue_txt),length(united_txt))
#Combine text of the airlines
airline<- c(delta_txt,jetblue_txt,united_txt)
Sentiment Analysis Application
score.sentiment = function(sentences, pos.words, neg.words, .progress='none')
{
scores = laply(sentences,
function(sentence, pos.words, neg.words)
{
sentence = gsub("[[:punct:]]", "", sentence)
sentence = gsub("[[:cntrl:]]", "", sentence)
sentence = gsub('\\d+', '', sentence)
tryTolower = function(x)
{
y = NA
try_error = tryCatch(tolower(x), error=function(e) e)
if (!inherits(try_error, "error"))
y = tolower(x)
return(y)
}
sentence = sapply(sentence, tryTolower)
word.list = str_split(sentence, "\\s+")
words = unlist(word.list)
pos.matches = match(words, pos.words)
neg.matches = match(words, neg.words)
pos.matches = !is.na(pos.matches)
neg.matches = !is.na(neg.matches)
score = sum(pos.matches) - sum(neg.matches)
return(score)
}, pos.words, neg.words, .progress=.progress )
# dataframe with scores
scores.df = data.frame(text=sentences, score=scores)
return(scores.df)
}
Processing the tweets to calculate the sentiment score.
scores = score.sentiment(airline, pos.words,neg.words , .progress='text')
##
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|==== | 7%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|====== | 10%
|
|======= | 10%
|
|======= | 11%
|
|======= | 12%
|
|======== | 12%
|
|======== | 13%
|
|========= | 13%
|
|========= | 14%
|
|========= | 15%
|
|========== | 15%
|
|========== | 16%
|
|=========== | 16%
|
|=========== | 17%
|
|=========== | 18%
|
|============ | 18%
|
|============ | 19%
|
|============= | 19%
|
|============= | 20%
|
|============= | 21%
|
|============== | 21%
|
|============== | 22%
|
|=============== | 22%
|
|=============== | 23%
|
|=============== | 24%
|
|================ | 24%
|
|================ | 25%
|
|================= | 25%
|
|================= | 26%
|
|================= | 27%
|
|================== | 27%
|
|================== | 28%
|
|=================== | 28%
|
|=================== | 29%
|
|=================== | 30%
|
|==================== | 30%
|
|==================== | 31%
|
|==================== | 32%
|
|===================== | 32%
|
|===================== | 33%
|
|====================== | 33%
|
|====================== | 34%
|
|====================== | 35%
|
|======================= | 35%
|
|======================= | 36%
|
|======================== | 36%
|
|======================== | 37%
|
|======================== | 38%
|
|========================= | 38%
|
|========================= | 39%
|
|========================== | 39%
|
|========================== | 40%
|
|========================== | 41%
|
|=========================== | 41%
|
|=========================== | 42%
|
|============================ | 42%
|
|============================ | 43%
|
|============================ | 44%
|
|============================= | 44%
|
|============================= | 45%
|
|============================== | 45%
|
|============================== | 46%
|
|============================== | 47%
|
|=============================== | 47%
|
|=============================== | 48%
|
|================================ | 48%
|
|================================ | 49%
|
|================================ | 50%
|
|================================= | 50%
|
|================================= | 51%
|
|================================= | 52%
|
|================================== | 52%
|
|================================== | 53%
|
|=================================== | 53%
|
|=================================== | 54%
|
|=================================== | 55%
|
|==================================== | 55%
|
|==================================== | 56%
|
|===================================== | 56%
|
|===================================== | 57%
|
|===================================== | 58%
|
|====================================== | 58%
|
|====================================== | 59%
|
|======================================= | 59%
|
|======================================= | 60%
|
|======================================= | 61%
|
|======================================== | 61%
|
|======================================== | 62%
|
|========================================= | 62%
|
|========================================= | 63%
|
|========================================= | 64%
|
|========================================== | 64%
|
|========================================== | 65%
|
|=========================================== | 65%
|
|=========================================== | 66%
|
|=========================================== | 67%
|
|============================================ | 67%
|
|============================================ | 68%
|
|============================================= | 68%
|
|============================================= | 69%
|
|============================================= | 70%
|
|============================================== | 70%
|
|============================================== | 71%
|
|============================================== | 72%
|
|=============================================== | 72%
|
|=============================================== | 73%
|
|================================================ | 73%
|
|================================================ | 74%
|
|================================================ | 75%
|
|================================================= | 75%
|
|================================================= | 76%
|
|================================================== | 76%
|
|================================================== | 77%
|
|================================================== | 78%
|
|=================================================== | 78%
|
|=================================================== | 79%
|
|==================================================== | 79%
|
|==================================================== | 80%
|
|==================================================== | 81%
|
|===================================================== | 81%
|
|===================================================== | 82%
|
|====================================================== | 82%
|
|====================================================== | 83%
|
|====================================================== | 84%
|
|======================================================= | 84%
|
|======================================================= | 85%
|
|======================================================== | 85%
|
|======================================================== | 86%
|
|======================================================== | 87%
|
|========================================================= | 87%
|
|========================================================= | 88%
|
|========================================================== | 88%
|
|========================================================== | 89%
|
|========================================================== | 90%
|
|=========================================================== | 90%
|
|=========================================================== | 91%
|
|=========================================================== | 92%
|
|============================================================ | 92%
|
|============================================================ | 93%
|
|============================================================= | 93%
|
|============================================================= | 94%
|
|============================================================= | 95%
|
|============================================================== | 95%
|
|============================================================== | 96%
|
|=============================================================== | 96%
|
|=============================================================== | 97%
|
|=============================================================== | 98%
|
|================================================================ | 98%
|
|================================================================ | 99%
|
|=================================================================| 99%
|
|=================================================================| 100%
Create a variable in the data frame.
scores$airline = factor(rep(c("Delta", "JetBlue","United"), noof_tweets))
# Calculate positive, negative and neutral sentiments.
scores$positive <- as.numeric(scores$score >0)
scores$negative <- as.numeric(scores$score <0)
scores$neutral <- as.numeric(scores$score==0)
#Split the data frame into individual datasets for each airline.
delta_airline <- subset(scores, scores$airline=="Delta")
jetblue_airline <- subset(scores,scores$airline=="JetBlue")
united_airline <- subset(scores,scores$airline=="United")
Create polarity variable for each data frame.
delta_airline$polarity <- ifelse(delta_airline$score >0,"Positive",
ifelse(delta_airline$score < 0,"Negative",
ifelse(delta_airline$score==0,"Neutral",0)))
jetblue_airline$polarity <- ifelse(jetblue_airline$score >0,"Positive",
ifelse(jetblue_airline$score < 0,"Negative",
ifelse(jetblue_airline$score==0,"Neutral",0)))
united_airline$polarity <- ifelse(united_airline$score >0,"Positive",
ifelse(united_airline$score < 0,"Negative",
ifelse(united_airline$score==0,"Neutral",0)))
Some Visualization Customer Sentiments (Delta Airlines)
qplot(factor(polarity), data=delta_airline, geom="bar",
fill=factor(polarity))+xlab("Polarity Categories") + ylab("Frequency") +
ggtitle("Customer Sentiments - Delta Airlines")
The bar graph above depicts polarity, it reveals that out of 2,000 twitter users, a little over 600 twitter users have commented in a negative way, a little over 800 users are neutral while less than 600 users are positive about Delta airline.
Customer Sentiment Scores (Delta Airlines)
qplot(factor(score), data=delta_airline, geom="bar",
fill=factor(score))+xlab("Sentiment Score") + ylab("Frequency") +
ggtitle("Customer Sentiment Scores - Delta Airlines")
The bar graph above indicates twitter user’s sentiment score, negative score denoted by the (-) symbol, which indicates unhappiness of users with the airline, whereas the positive score denotes that users are happy with the airline. While, zero represents that twitter users are neutral.
Polarity Plot – Customer Sentiments (JetBlue Airlines)
qplot(factor(polarity), data=jetblue_airline, geom="bar",
fill=factor(polarity))+xlab("Polarity Categories") + ylab("Frequency") +
ggtitle(" Customer Sentiments - JetBlue Airlines ")
The bar graph above represents polarity, out of the 2,000 twitter users,about 450 users have commented negatively, over 800 users remain neutral while a over 600 users are positive about the airline.
Customer Sentiment Scores (JetBlue Airlines)
qplot(factor(score), data=jetblue_airline, geom="bar",
fill=factor(score))+xlab("Sentiment Score") + ylab("Frequency") +
ggtitle("Customer Sentiment Scores - JetBlue Airlines")
The graph above shows twitter user’s sentiment score, the negative score indicates unhappiness with the airline, whereas the positive score indicates that the twitter users are happy.
Polarity Plot – Customer Sentiments (United Airlines)
qplot(factor(polarity), data=united_airline, geom="bar",
fill=factor(polarity))+xlab("Polarity Categories") + ylab("Frequency") +
ggtitle("Customer Sentiments - United Airlines")
Out of the 2,000 twitter users, about 300 users have commented negatively while about 1,250 users remain neutral and about 500 users positive about the United airline.
Customer Sentiment Scores (United Airlines)
qplot(factor(score), data=united_airline, geom="bar",
fill=factor(score))+xlab("Sentiment Score") + ylab("Frequency") +
ggtitle("Customer Sentiment Scores - United Airlines ")
The graph above indicates that twitter user’s sentiment score of negative indicates unhappiness of users with the United airline while the positive score indicates users are happy with the airline and zero indicates users are neutral.
Conclusion
According to Bowen and Headley (2019), the Airline Quality Rating industry score for 2018 shows an industry that improved in overall performance quality over the previous year. Six airlines (Delta, Hawaiian, JetBlue, Southwest, Spirit, and United) showed improvement in AQR scores in 2018.
Sentiment analysis enables companies to understand consumer sentiments in relation to specific products/services. The analysis of these sentiments may be useful to improve their products and customer satisfaction.
This analysis support the AQR rating as indicated from paragragh one of this conclusion, Delta, JetBlue and United are among the six airlines listed above with improved AQR score for year ending 2018. The analysis also shows that twitter sentiment can have effect on airline reputation which answers the research question “does twitter sentiment have effect on Airline Reputation?”.
Reference Bowen, B. D., & Headley, D. E. (2019). Airline Quality Rating 2019.Retrieved from https://commons.erau.edu/aqrr/29