Description Usage Arguments Value Query resolution Categories Examples
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | gtrends(query, geo, cat, gprop, session, ...)
## Default S3 method:
gtrends(query = "", geo = "", cat = "0", gprop = c("",
"news", "images", "froogle", "youtube"), session, res = c(NA, "1h", "4h",
"1d", "7d"), start_date = as.Date("2004-01-01"),
end_date = as.Date(Sys.time()), ...)
## S3 method for class 'gtrends'
summary(object, ...)
## S3 method for class 'gtrends'
plot(x, type = c("trend", "geo"), which = 5, ind = 1L,
...)
## S3 method for class 'gtrends'
as.zoo(x, ...)
|
query |
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 |
cat |
A character denoting the category, defaults to “0”. |
gprop |
A character string defining the Google product for which the trend query if preformed. Valid options are “” (empty string - web search), “news”, “images”, “froogle” and “youtube”. Default is “”. |
session |
A valid session which can be created via
|
... |
Additional parameters passed on in method dispatch. |
res |
Resolution of the trending data to be returned. One of
|
start_date |
Starting date using yyyy-mm-dd format. Must be greater than 2004-01-01. |
end_date |
Starting date using yyyy-mm-dd format. Must be before than current date. |
object |
A |
x |
A |
type |
A character variable selecting the type of plot; permissible values are ‘trends’ (which is also the default), ‘geo’. |
which |
Block number containing the geographical data to plot. |
ind |
A integer selecting the result set in case of multiple search terms. |
An object of class ‘gtrends’ which is list with six elements containing the results.
When type
is equal to ‘trends’, the resulting
ggplot2 object is returned silently.
By default, Google returns weekly information when the requested data spans a period greater than three months. It is also possible to obtain daily and hourly information. However, these are only available for a certain period prior to the current date.
For instance, 1h
, 7h
, 1d
and 7d
denote trends
data for the last 1 hour, last four hours, last day and last seven day
respectively. Using one of the above res
will return the
corresponding hourly data.
Note that data requested for a beriod between one and three months will be returned daily. For a period greater than three months, data will be always returned weekly.
The package includes a complete list of categories that
can be used to narrow requests. These can be accessed using
data("categories")
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ## Not run:
session <- gconnect("usr@gmail.com", "psw")
gtrends(c("NHL", "NBA", "MLB", "MLS"))
gtrends("NHL", geo = c("CA", "US"))
# Search only for the sport category.
gtrends("NHL", geo = c("CA", "US"), cat = "0-20")
# Trends between 2015-01-01 and 2015-03-01 in Sweeden. Will be daily data.
gtrends("NHL", geo = c("SE"), start_date = "2015-01-01", end_date = "2015-03-01")
# Trends between 2015-01-01 and 2015-04-01 in Sweeden. Will be weekly data.
gtrends("NHL", geo = c("SE"), start_date = "2015-01-01", end_date = "2015-04-01")
# Last 4 hours trends
gtrends("NHL", geo = c("CA"), res = "4h")
# Last 7 days trends
gtrends("NHL", geo = c("CA"), res = "7d")
# Using categories
data("categories")
categories[grepl("music", categories$name, ignore.case = TRUE), ]
gtrends(cat = "1087")
## End(Not run)
data("sport_trend")
plot(sport_trend)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.