Using R to query Google Trends and Ngrams

1 minute read

Published:

Lately I’ve been toying with the idea of comparing how popular different people and ideas are. I’ve already queried Wikipedia page views in R, but I wondered whether I could do something similar with Google Trends or Google Ngrams. Both give an interesting sense of the relative popularity of a query, and, luckily for me, other people have already built brilliant bridges between R and Google Trends and Google Ngrams.

As an experimental psychologist, one thing that caught my eye was the shifting popularity of two psychoanalysts, Sigmund Freud and Carl Jung. Given that psychology keeps getting more empirical, I expected these two gentlemen to be losing their shine over time.

Google Ngrams shows both psychoanalysts peaking around 1995, with the relative frequency of their names falling away since.

Google Ngram - Freud vs. Jung
Google Ngram - Freud vs. Jung

The Ngram data stops at 2008, though, so things could have moved on since. To check, I queried Google Trends, which shows the relative frequency of search terms. I didn’t set a locale in the function, so I assume the results are global (though I used the English spellings of the names).

Google Trends backs up the Ngram picture: on this measure too, both Freud and Jung are in decline.

Google Trends - Freud vs. Jung
Google Trends - Freud vs. Jung

This was only a quick write-up, so feel free to take the code and run with it: