Data Journalism in R

Exploring Beto O’Rourke and Ted Cruz ads on Facebook using R

When and how often are Beto O’Rourke ads being rolled out on Facebook and who is paying for them? What is the sentiment of those ads and how do Beto’s ads differ in sentiment from his opponent Ted Cruz’s?

Using more than 94,000 Facebook ads collected by ProPublica’s Political Ad Collector, I attempted to answer those questions using the R packages “tidytext” for textual and sentiment analysis, “ggplot2” and “plotly” for data visualization, and “dplyr,” “stringr” and “tidyverse” for data wrangling.

Beto has spent more than $6 million on Facebook ads in the last six months – ten times what Ted Cruz has spent on the platform, according to the Texas Tribune. ProPublica’s dataset is by no means a random sample but it shows this general trend. Below, Beto’s ads are highlighted in blue plotted alongside every advertiser that ran ads mentioning either “Beto” or “Cruz.”

Unsurprisingly, the ads seem to be ramping up as the midterm elections approach. (The size of the dots are mapped to the number of impressions, described by ProPublica as the “number of times the ad has been seen by the Political Ad Collector.”)

Breaking out the ads that were paid for by the Beto and Cruz campaigns, we can juxtapose the two and reveal just how much more Beto’s is relying on the platform (at least as captured by ProPublica’s project).

Next, I applied sentiment analysis to the ads the O’Rourke and Cruz campaigns ran on Facebook (as caught in this dataset.) On average, their ads were slightly above neutral, with O’Rourke’s at 0.318 and Cruz’s a bit more negative at 0.211.

DON’T MISS  How to download YouTube data in R using "tuber" and "purrr"

 

 

One final question I had was who were the most negative advertisers outside of the campaigns themselves? Turns out folks like UltraViolet, End Citizens United and Enough is Enough Voter Project drove overwhelmingly negative ads. What did those look like?

  • “Ted Cruz vowed to bring criminal charges against Planned Parenthood, then he called the war on women ‘nonsense.'” – UltraViolet
  • “Ted Cruz JUST released a wave of attack ads against Beto O’Rourke — and it’s BAD!! Cruz is TERRIFIED that Beto will demolish him in November” – End Citizens United
  • “Ted Cruz votes against victims of sexual abuse and rape time and time again. We are saying enough is enough. Join us!” – Enough is Enough Voter Project

 

 

Full code is here.

 

Aleszu Bajak
Latest posts by Aleszu Bajak (see all)
DON’T MISS  How to plot state-by-state data on a map of the U.S. in R

2 thoughts on “Exploring Beto O’Rourke and Ted Cruz ads on Facebook using R

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest from Storybench

Keep up with tutorials, behind-the-scenes interviews and more.