Using Google Trends data 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:

  1. Select Insert > Analysis > More > Data > Google Trends.
  2. 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.

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 google searches for the topic blu-ray from 2004 to present. I have left the Region with the default value of World.

To visualize the results from the table,

  1. Select Insert > Visualization > Line Chart.
  2. Choose the Google Trends results in the Table section in the Object Inspector to the right.

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.

Google 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 multiple countries can be obtained by setting Region to Multiple regions and entering a comma-separated list into the Region codes field of your Google Trends output options.

The awkward part about geographic codes is that they are not always obvious. Country codes consist of two letters, for example CA and NZ in this case. There is also the option to use state codes such as US-CA for California. I find the easiest way to get these codes is to look through the Region list, or 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) = sort(unique(countries[substr(countries$sub_code, 1, 2) == "IT", ]$sub_code))

The google trends search history of skiing from 2010 to 2017 is plotted below.  I did not check the Long format output 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.

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 google search trends 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.