Google Trends is feeling the Bern
I was interested in what Google Trends trends might be able to tell us about the US primaries. Thought it would be good practice for my basic R skills.
So, first things first, I downloaded some packages. I like the old themes package for easy ggplot graphics.
install.packages('stringr') library(stringr) install.packages('lubridate') library(lubridate) install.packages('ggplot2') library(ggplot2) install.packages('reshape') library(reshape) devtools::install_github("jrnold/ggthemes") library(ggthemes)
Next, annoyingly, I had to go manual since I do not know how to download data direct into R from the Google Trends site. I searched for the five main candidates over the past 12 months. Here. I then downloaded the csv file into my R project directory, and called it ‘g’.
Edited the weekly data, and put it into date format with lubridate.
g$Week <- str_sub(g$Week, end= 10) g$Week <- ymd(g$Week)
Sorted out our candidate names.
cands <- c("Cruz", "Clinton", "Sanders", "Trump", "Rubio") colnames(g) <- c("Week", cands)
Melted the data to get it ready for charting.
g <- melt(g, id="Week")
Charted the data.
ggplot(g, aes(x=Week, y=value, color=variable)) + geom_line() + theme_economist() + ylab("Google search interest relative to the highest point on the chart") +xlab("The last 12 months") + theme(legend.position=c(.2, .86)) + theme(legend.title=element_blank())
The national search data suggests Trump remains the GOP candidate to beat. Cruz remains in second place, while Rubio, though up, is still struggling.
The data for the Democrat race, though, is way more interesting. Look at Sanders’ numbers - in the last couple of weeks he has been killing Clinton nationally in search interest. Now, I know, he’s the rock-star de jour, while everyone knows Clinton. And there’s no guarantee that people who are just finding out about him will then vote for him. And, besides, the next few months are about state primaries well away from the People’s Republic of New Hampshire. Indeed - the next two Democratic primaries, Nevada and South Carolina (Feb 20, 27), Clinton is expected to win. She needs to win.
But Google search data suggests she’s in danger. This is what happened in New Hampshire with Google search trends in the lead up to the primary on Feb 9. And this is what’s happening in Nevada and South Carolina - tell me they do not look similar.