Title: | Perform and Display Google Trends Queries |
---|---|
Description: | An interface for retrieving and displaying the information returned online by Google Trends is provided. Trends (number of hits) over the time as well as geographic representation of the results can be displayed. |
Authors: | Philippe Massicotte [aut, cre], Dirk Eddelbuettel [aut] |
Maintainer: | Philippe Massicotte <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.5.1.9000 |
Built: | 2024-11-23 04:48:53 UTC |
Source: | https://github.com/pmassicotte/gtrendsr |
name Names of the categories
id IDs of the categories
data("categories")
data("categories")
A data frame with 1426 rows and 2 variables
country_code Two-digits country codes
description Description of the location
sub_code ISO3166-2 country codes
data("countries")
data("countries")
A data frame with 117293 rows and 3 variables
https://www.unece.org/cefact/codesfortrade/codes_index.html
Extract top and rising searches
extract_top_rising(data)
extract_top_rising(data)
data |
Data returned by a search query. |
A list with TOP and RISING data (if such data was found).
The gtrends
default method performs a Google Trends query for the
‘query’ argument and session ‘session’. Optional arguments for
geolocation and category can also be supplied.
gtrends( keyword = NA, geo = "", time = "today+5-y", gprop = c("web", "news", "images", "froogle", "youtube"), category = 0, hl = "en-US", compared_breakdown = FALSE, low_search_volume = FALSE, cookie_url = "http://trends.google.com/Cookies/NID", tz = 0, onlyInterest = FALSE )
gtrends( keyword = NA, geo = "", time = "today+5-y", gprop = c("web", "news", "images", "froogle", "youtube"), category = 0, hl = "en-US", compared_breakdown = FALSE, low_search_volume = FALSE, cookie_url = "http://trends.google.com/Cookies/NID", tz = 0, onlyInterest = FALSE )
keyword |
A character vector with the actual Google Trends query
keywords. Multiple keywords are possible using |
geo |
A character vector denoting geographic regions for the query,
default to “all” for global queries. Multiple regions are possible
using |
time |
A string specifying the time span of the query. Possible values are:
|
gprop |
A character string defining the Google product for which the trend query if preformed. Valid options are:
|
category |
A character denoting the category, defaults to “0”. |
hl |
A string specifying the ISO language code (ex.: “en-US” or “fr”). Default is “en-US”. Note that this is only influencing the data returned by related topics. |
compared_breakdown |
Logical. Should compare breakdown the results by city and subregion? Can only be used if one 'geo' is used conjointly with more than one keyword. If 'TRUE', then the relative hits across the keywords will be returned. 'FALSE' by default. |
low_search_volume |
Logical. Should include low search volume regions? |
cookie_url |
A string specifying the URL from which to obtain cookies. Default should work in general; should only be changed by advanced users. |
tz |
A number specifying the minutes the returned dates should be offset to UTC. Note the parameter 'time' above is specified in UTC. E.g. choosing "time=2018-01-01T01 2018-01-01T03" and "tz=-120" will yield data between 2018-01-01T03 and 2018-01-01T05, i.e. data specified to be in UTC+2. |
onlyInterest |
If you only want the interest over time set it to TRUE. |
An object of class ‘gtrends’ (basically a list of data frames).
The package includes a complete list of categories that
can be used to narrow requests. These can be accessed using
data("categories")
.
Note that *related topics* are not retrieved when more than one keyword is provided due to Google restriction.
## Not run: head(gtrends("NHL")$interest_over_time) head(gtrends("NHL")$related_topics) head(gtrends("NHL")$related_queries) head(gtrends(c("NHL", "NFL"))$interest_over_time) head(gtrends(c("NHL", "NFL"), geo = c("CA", "US"))$interest_over_time) ## Interest by city gtrends(keyword = "obama", geo = "US-AL-630") ## Sport category (20) data(categories) categories[grepl("^Sport", categories$name), ] gtrends(c("NHL", "NFL"), geo = c("CA", "US"), category = 20) gtrends(geo = c("CA"), category = 20) ## Playing with time format gtrends(c("NHL", "NFL"), time = "now 1-H") # last hour gtrends(c("NHL", "NFL"), time = "now 4-H") # last four hours gtrends(c("NHL", "NFL"), time = "now 1-d") # last day gtrends(c("NHL", "NFL"), time = "today 1-m") # last 30 days gtrends(c("NHL", "NFL"), time = "today 3-m") # last 90 days gtrends(c("NHL", "NFL"), time = "today 12-m") # last 12 months gtrends(c("NHL", "NFL"), time = "today+5-y") # last five years (default) gtrends(c("NHL", "NFL"), time = "all") # since 2004 ## Custom date format gtrends(c("NHL", "NFL"), time = "2010-01-01 2010-04-03") ## Search from various Google's services head(gtrends(c("NHL", "NFL"), gprop = "news")$interest_over_time) head(gtrends(c("NHL", "NFL"), gprop = "youtube")$interest_over_time) ## Language settings head(gtrends("NHL", hl = "en")$related_topics) head(gtrends("NHL", hl = "fr")$related_topics) ## Compared breakdown head(gtrends(keyword = c("nhl", "nba"), geo = "CA", compared_breakdown = FALSE)$interest_by_region) head(gtrends(keyword = c("nhl", "nba"), geo = "CA", compared_breakdown = TRUE)$interest_by_region) ## End(Not run)
## Not run: head(gtrends("NHL")$interest_over_time) head(gtrends("NHL")$related_topics) head(gtrends("NHL")$related_queries) head(gtrends(c("NHL", "NFL"))$interest_over_time) head(gtrends(c("NHL", "NFL"), geo = c("CA", "US"))$interest_over_time) ## Interest by city gtrends(keyword = "obama", geo = "US-AL-630") ## Sport category (20) data(categories) categories[grepl("^Sport", categories$name), ] gtrends(c("NHL", "NFL"), geo = c("CA", "US"), category = 20) gtrends(geo = c("CA"), category = 20) ## Playing with time format gtrends(c("NHL", "NFL"), time = "now 1-H") # last hour gtrends(c("NHL", "NFL"), time = "now 4-H") # last four hours gtrends(c("NHL", "NFL"), time = "now 1-d") # last day gtrends(c("NHL", "NFL"), time = "today 1-m") # last 30 days gtrends(c("NHL", "NFL"), time = "today 3-m") # last 90 days gtrends(c("NHL", "NFL"), time = "today 12-m") # last 12 months gtrends(c("NHL", "NFL"), time = "today+5-y") # last five years (default) gtrends(c("NHL", "NFL"), time = "all") # since 2004 ## Custom date format gtrends(c("NHL", "NFL"), time = "2010-01-01 2010-04-03") ## Search from various Google's services head(gtrends(c("NHL", "NFL"), gprop = "news")$interest_over_time) head(gtrends(c("NHL", "NFL"), gprop = "youtube")$interest_over_time) ## Language settings head(gtrends("NHL", hl = "en")$related_topics) head(gtrends("NHL", hl = "fr")$related_topics) ## Compared breakdown head(gtrends(keyword = c("nhl", "nba"), geo = "CA", compared_breakdown = FALSE)$interest_by_region) head(gtrends(keyword = c("nhl", "nba"), geo = "CA", compared_breakdown = TRUE)$interest_by_region) ## End(Not run)
Plot Google Trends interest over time
## S3 method for class 'gtrends' plot(x, ...)
## S3 method for class 'gtrends' plot(x, ...)
x |
A |
... |
Additional parameters passed on in method dispatch. Currently not used. |
A ggplot2 object is returned silently.
## Not run: res <- gtrends("nhl", geo = c("CA", "US")) plot(res) ## End(Not run)
## Not run: res <- gtrends("nhl", geo = c("CA", "US")) plot(res) ## End(Not run)
gtrends
should be used behind a proxy, especially with NTLM
authentication mode, you need to set the proxy parameters and credentials
using "setHandleParameters" functionIf gtrends
should be used behind a proxy, especially with NTLM
authentication mode, you need to set the proxy parameters and credentials
using "setHandleParameters" function
setHandleParameters( user = NULL, password = NULL, domain = NULL, proxyhost = NULL, proxyport = 8080, proxyauth = 15, extra_curl_opts = list() )
setHandleParameters( user = NULL, password = NULL, domain = NULL, proxyhost = NULL, proxyport = 8080, proxyauth = 15, extra_curl_opts = list() )
user |
A string specifying your username |
password |
A string specifying your password |
domain |
A string specifying the authentication domain |
proxyhost |
A string specifying the Proxy host DNS or IP address |
proxyport |
A numeric specifying the Proxy Port : 8080 (default) |
proxyauth |
A numeric specifying the Proxy Authentication Method : 0 for NONE 1 for BASIC 2 for DIGEST 4 for NEGOTIATE 8 for NTLM 15 for ANY (default) |
extra_curl_opts |
A list of additional named options to pass into curl::handle_setopt(), e.g. list(timeout=60) |
## Not run: library(gtrendsR) setHandleParameters( user = "xxxx", password = "*******", domain = "mydomain", proxyhost = "10.111.124.113" ) res <- gtrends(c("nhl", "nba"), geo = c("CA", "US")) # include additional curl options setHandleParameters( user = "xxxx", password = "*******", domain = "mydomain", proxyhost = "10.111.124.113", extra_curl_opts = list(timeout = 60) ) ## End(Not run)
## Not run: library(gtrendsR) setHandleParameters( user = "xxxx", password = "*******", domain = "mydomain", proxyhost = "10.111.124.113" ) res <- gtrends(c("nhl", "nba"), geo = c("CA", "US")) # include additional curl options setHandleParameters( user = "xxxx", password = "*******", domain = "mydomain", proxyhost = "10.111.124.113", extra_curl_opts = list(timeout = 60) ) ## End(Not run)