https://github.com/cdcgov/gtrendshealth

Connects to the Google Trends for Health API, allowing projects authorized to use the health research data to query Google Trends.

https://github.com/cdcgov/gtrendshealth

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.7%) to scientific vocabulary

Keywords

api google infodemiology r trends
Last synced: 5 months ago · JSON representation

Repository

Connects to the Google Trends for Health API, allowing projects authorized to use the health research data to query Google Trends.

Basic Info
  • Host: GitHub
  • Owner: CDCgov
  • License: other
  • Language: R
  • Default Branch: main
  • Homepage:
  • Size: 61.5 KB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
api google infodemiology r trends
Created 8 months ago · Last pushed 8 months ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---




```{r}
#| echo: false
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)
```




# gtrendshealth: Query the Google Trends for Health API



[![R-CMD-check](https://github.com/CDCgov/gtrendshealth/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/CDCgov/gtrendshealth/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/CDCgov/gtrendshealth/graph/badge.svg)](https://app.codecov.io/gh/CDCgov/gtrendshealth)



## Overview

This package connects to the Google Trends for Health API to query Google
Trends for projects authorized to use the health research data.
It fetches a graph of search volumes per time within a set of restrictions.
Each term will result in a timeline of search over time.
Note the data is sampled and Google can't guarantee the accuracy of the numbers.
This service is closed to a subset of Health researchers.
The quota provision is individually maintained by the Trends team.

You will need an API key from your Google Developer project authorized for
Google Trends for Health API use.
A key can be acquired by requesting access at
https://support.google.com/trends/contact/trends_api
and following the setup instructions.




## Installation

Install the package from CRAN using:

```{r eval=FALSE}
install.packages("gtrendshealth")
```


Install the development version from CDCgov GitHub using:

```{r eval=FALSE}
remotes::install_github("CDCgov/gtrendshealth")
```




## Usage

After receiving access to the Google Trends for Health API and setting up your
Google Developer project, generate an API key, and set it up for use in your R
installation:




```{r}
#| label: setup
#| eval: FALSE
library(package = "gtrendshealth")

set_gt_api_key(
  key = "{your-key}",
  install = TRUE
)
```




By default, the key is installed in the `.Renviron` file in your home folder,
and will be loaded into the `GOOGLE_TRENDS_FOR_HEALTH_API_KEY` environment
variable every time you start R.
If you only want the key for the active session, use `install = FALSE`.




```{r}
#| label: example
#| cache: true
#| fig.alt: "Time series of Google search volume for the term _fever_ in the US,
#|  with weekly and monthly resolution"
library(package = "gtrendshealth")

# Query the Google Trends for Health service
monthly_trends <- get_health_trends(
  terms = "fever",
  resolution = "month",
  start = as.Date("2024-01-01"),
  end = as.Date("2024-12-31"),
  country = "US"
)

# set a date for each monthly observation
# using the 15th of each month for the day
monthly_trends$date <- as.Date(
  strptime(
    paste("15", monthly_trends$period),
    format = "%d %b %Y"
  )
)

head(monthly_trends)

# Query the Google Trends for Health service
daily_trends <- get_health_trends(
  terms = "fever",
  resolution = "day",
  start = as.Date("2024-01-01"),
  end = as.Date("2024-12-31"),
  country = "US"
)

head(daily_trends)

# plot the time series
plot(
  daily_trends$date, daily_trends$value, type = "l", col = "blue",
  xlab = "Date",
  ylab = "Probability (x10 M)",
  main = paste(
    "Daily and Monthly Trends in Interest",
    "\nfor the term Fever in the US, 2024"
  )
)
lines(monthly_trends$date, monthly_trends$value, col = "red", lwd = 2)
legend("topleft", legend = c("Daily Trends", "Monthly Trends"),
       col = c("blue", "red"), lty = 1, lwd = c(1, 2))
```

Owner

  • Name: Centers for Disease Control and Prevention
  • Login: CDCgov
  • Kind: organization
  • Email: data@cdc.gov
  • Location: Atlanta, GA

CDC's collaborative software projects to protect America from health, safety, and security threats, both foreign and in the U.S.

GitHub Events

Total
  • Push event: 4
  • Create event: 1
Last Year
  • Push event: 4
  • Create event: 1

Packages

  • Total packages: 1
  • Total downloads:
    • cran 150 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
cran.r-project.org: gtrendshealth

Query the 'Google Trends for Health' API

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 150 Last month
Rankings
Dependent packages count: 26.2%
Dependent repos count: 32.3%
Average: 48.3%
Downloads: 86.5%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v4 composite
  • actions/upload-artifact v4 composite
  • codecov/codecov-action v5 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • R >= 4.1.0 depends
  • httr * imports
  • jsonlite * imports
  • utils * imports
  • testthat >= 3.0.0 suggests