25 August 2017 |
Analyzing Google Trends Data in Displayr
Using Google Trends can add further texture to your analysis by providing a history of how popular a topic is (or was) on the Internet. It can be used to identify terms with growing or decreasing popularity, or to review periodic variations from the past.
This post describes how you can use Displayr to easily extract data from Google Trends, and then include it in a chart or other analysis. We’ll discuss first how you can get overall (global) data on the search term, and then how you can get results for particular regions.
Global example: The rise and fall of blu-ray
I have never bought a blu-ray and probably never will. In my world, technology moved from DVDs to streaming without the need for a high definition physical medium. I still see them in some shops, but it feels as though they are declining. Using Google Trends we can find out when interest in blu-rays peaked.
Getting started is easy:
- Select Insert > More > Marketing > Google Trends.
- Enter a search term in the Topic(s) box in the Object Inspector to the right. If you want to include multiple topics the just separate them by commas.
- Click Calculate.
The other options that are available allow you to choose the historical time period and whether the queries are for the web, news or images. The analysis can also be narrowed down by geography (more on this below).
The table below shows the raw history of searches for the topic blu-ray from 2004 to present. I have left the Geographic code(s) blank, which returns data for the whole world.
To visualize the results from the table,
- Select Insert > Visualization > Line Chart.
- Choose the Google Trends results in the Table section in the Object Inspector to the right.
- Click Calculate.
From the chart we can draw two conclusions. First, interest peaked around the end of 2008. Second, there is a strong seasonal effect, with significant spikes around Christmas every year.
Note that results are relative to the total number of searches at each time point, with the maximum being 100. We cannot infer anything about the volume of Google searches. But we can say that as a proportion of all searches blu-ray was about half as frequent in June 2008 compared to December 2008. See this link for more explanation about Google’s methodology.
Trends by geographic region
Next I will illustrate the use of country codes. To do so I will find the search history for skiing in Canada and New Zealand. Results for individual regions can be obtained by entering a comma-separated list of region codes into the Geographic code(s) field of your Google Trends output options.
The awkward part about geographical codes is that they are not always obvious. Country codes consist of two letters, for example CA and NZ in this case. We could also use region codes such as US-CA for California. I find the easiest way to get these codes is to use this Wikipedia page.
An alternative method for finding all the region-level codes for a given country is to use the following snippet of R code. In this case it retrieves all the regions of Italy (IT). To run this in Displayr, select Insert > R Output, paste in the code, and click Calculate.
library(gtrendsR) geo.codes = sort(unique(countries[substr(countries$sub_code, 1, 2) == "IT", ]$sub_code))
The search history of skiing from 2010 to 2017 is plotted below. I did not check the As data.frame box in Displayr. This means that the result is a table with dates labelling the rows and countries along the columns. If the box was checked, the result would be one row for each country for each date, which is know as long format.
Looking at the chart below, we note the contrast between northern and southern hemisphere winters. Skiing is also relatively more popular in Canada than New Zealand. The 2014 winter Olympics causes a notable spike in both countries, but particularly Canada.
In this post I have shown how to import data from Google Trends into Displayr. You can follow my steps, or play around with your own queries (why not try bitcoin?) in Displayr by following this link.
Author: Jake Hoare
After escaping from physics to a career in banking, then escaping from banking, I decided to go back to BASIC and study computing. This led me to rediscover artificial intelligence and data science. I now get to indulge myself at Displayr working in the Data Science team, sometimes on machine learning.