| Title: | Access 'Google Charts' Map Data |
|---|---|
| Description: | Connects to the 'Google Charts' geographic data resources described in <https://developers.google.com/chart/interactive/docs/gallery/geochart>, allowing the user to download contents to use as a reference for related services like 'Google Trends'. |
| Authors: | Oscar de Leon [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-1344-4412>) |
| Maintainer: | Oscar de Leon <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.1 |
| Built: | 2026-05-11 07:00:14 UTC |
| Source: | https://github.com/odeleongt/gchartsmap |
Get a list of areas that have been downloaded
gchart_available_areas( type = c("countries", "us-areas"), cache = gchart_get_cache_path() )gchart_available_areas( type = c("countries", "us-areas"), cache = gchart_get_cache_path() )
type |
Type of geo-resource. Defaults to countries. |
cache |
Path where the downloaded data is stored. |
Ensure that the cache directory exists
gchart_cache_dir( path = tools::R_user_dir(package = "gchartsmap", which = "cache") )gchart_cache_dir( path = tools::R_user_dir(package = "gchartsmap", which = "cache") )
path |
Path to verify |
Extracts the list of available countries from the Google Charts documentation
gchart_countries( server = "https://developers.google.com/chart/interactive/docs/gallery/geochart", cache = gchart_get_cache_path(), format = c("rds", "rda"), update = FALSE, verbose = TRUE )gchart_countries( server = "https://developers.google.com/chart/interactive/docs/gallery/geochart", cache = gchart_get_cache_path(), format = c("rds", "rda"), update = FALSE, verbose = TRUE )
server |
Location for the relevant Google Charts documentation. Use the default. |
cache |
Path to store downloaded data. |
format |
Which format to use for storing the countries table. |
update |
Whether to update the table even if it is cached. |
verbose |
Whether to show messages during processing. |
Extracts the information of countries available in the Google Charts geochart service from the online documentation
A data.frame with information for all countries available in
the service.
This function queries 'Google Charts' resources to identify countries for which geographical data is available, and generates the simple features for local use.
gchart_generate_countries( countries = "all", server = "https://www.gstatic.com/charts/geochart/10/mapfiles/", cache = gchart_get_cache_path(), verbose = TRUE )gchart_generate_countries( countries = "all", server = "https://www.gstatic.com/charts/geochart/10/mapfiles/", cache = gchart_get_cache_path(), verbose = TRUE )
countries |
Which countries to process. Defaults to "all".
Use country codes from |
server |
Google geochart server to access. |
cache |
Path to store downloaded data. |
verbose |
Whether to show messages during processing. |
Returns a simple features 'data.frame' with class 'sf', representing the spatial data for all countries from the Google Charts servers, using the WGS84 (epsg = 4326) coordinate reference system. You need to first run 'gchart_set_cache()' so the package knows where to store the downloaded data.
library(package = "gchartsmap") # set the cache path to your system's cache path gchartsmap::gchart_set_cache(path = tempdir()) # GET and process all countries gchartsmap::gchart_generate_countries(countries = "GT") # clean up list.files( tempdir(), all.files = TRUE, full.names = TRUE, recursive = TRUE )library(package = "gchartsmap") # set the cache path to your system's cache path gchartsmap::gchart_set_cache(path = tempdir()) # GET and process all countries gchartsmap::gchart_generate_countries(countries = "GT") # clean up list.files( tempdir(), all.files = TRUE, full.names = TRUE, recursive = TRUE )
This function queries 'Google Charts' resources to identify the US geographic areas used in services like Google Trends, and uses geographic data from the US Census Bureau to provide those areas with subdivisions at the county level.
gchart_generate_us_areas(areas = 1:1000L, limit = 1000)gchart_generate_us_areas(areas = 1:1000L, limit = 1000)
areas |
Area codes to get. Should be integers. |
limit |
Maximum number of areas to look for. |
Returns a simple features 'data.frame' with class 'sf', representing the spatial data for all areas with a valid id between 1 and a 1000 from the Google Charts servers, using the WGS84 (epsg = 4326) coordinate reference system. You need to first run 'gchart_set_cache()' so the package knows where to store the downloaded data.
library(package = "gchartsmap") # set the cache path to your system's cache path gchartsmap::gchart_set_cache(path = tempdir()) # GET and process area 500 gchartsmap::gchart_generate_us_areas(500L) # clean up list.files( tempdir(), all.files = TRUE, full.names = TRUE, recursive = TRUE )library(package = "gchartsmap") # set the cache path to your system's cache path gchartsmap::gchart_set_cache(path = tempdir()) # GET and process area 500 gchartsmap::gchart_generate_us_areas(500L) # clean up list.files( tempdir(), all.files = TRUE, full.names = TRUE, recursive = TRUE )
Get the saved cache path
gchart_get_cache_path(path = NULL)gchart_get_cache_path(path = NULL)
path |
Path to use as cache |
Returns the path to the local cache as set in the 'R_GOOGLE_CHART_CACHE' environment variable. If that is not set, gets the system's default cache path for the package as provided by 'tools::R_user_dir()'.
library(package = "gchartsmap") # set the cache path to a temp folder gchartsmap::gchart_set_cache(path = tempdir()) # check the set cache gchartsmap::gchart_get_cache_path()library(package = "gchartsmap") # set the cache path to a temp folder gchartsmap::gchart_set_cache(path = tempdir()) # check the set cache gchartsmap::gchart_get_cache_path()
Access the Google Charts geochart data for countries
gchart_get_countries( countries = "all", server = "https://www.gstatic.com/charts/geochart/10/mapfiles/", cache = gchart_get_cache_path(), verbose = FALSE )gchart_get_countries( countries = "all", server = "https://www.gstatic.com/charts/geochart/10/mapfiles/", cache = gchart_get_cache_path(), verbose = FALSE )
countries |
Country codes to get. |
server |
Google geochart server to access. |
cache |
Path to store downloaded data. |
verbose |
Whether to show messages during processing. |
The function invisibly returns the file path for successful requests or the response status code for failed requests, in a character vector with the country code for each element.
Access the Google Charts geochart data for US areas
gchart_get_us_areas( areas, server = "https://www.gstatic.com/charts/geochart/10/mapfiles/", cache = gchart_get_cache_path(), limit = 1000 )gchart_get_us_areas( areas, server = "https://www.gstatic.com/charts/geochart/10/mapfiles/", cache = gchart_get_cache_path(), limit = 1000 )
areas |
Area codes to get. Should be integers. |
server |
Google geochart server to access. |
cache |
Path to store downloaded data. |
limit |
Maximum number of areas to look for |
The function invisibly returns the file path for successful requests or the response status code for failed requests, in a character vector with the area name for each element.
Process the downloaded Google Charts geochart data for US areas
gchart_process_areas( areas, type = c("countries", "us-areas"), cache = gchart_get_cache_path() )gchart_process_areas( areas, type = c("countries", "us-areas"), cache = gchart_get_cache_path() )
areas |
Area codes to get. Should be integers. If not provided, all available areas are processed. |
type |
Type of geo-resource. Defaults to countries. |
cache |
Path where the downloaded data is stored. |
Google Charts data is served as JavaScript code that defines objects with the desired data. This function processes the locally-available Google Charts js files to generate spatial objects.
Ensures that the directory exists and sets the environment variable for access.
gchart_set_cache( path = tools::R_user_dir(package = "gchartsmap", which = "cache"), install = FALSE, overwrite = FALSE, home = "HOME" )gchart_set_cache( path = tools::R_user_dir(package = "gchartsmap", which = "cache"), install = FALSE, overwrite = FALSE, home = "HOME" )
path |
Path to use for the package cache. |
install |
if TRUE, will install the cache path in your |
overwrite |
If this is set to TRUE, it will overwrite an existing
cache path that you already have in your |
home |
Path for the |
Sets and returns the path to the cache where downloaded data will be stored. Is used for the side effect of setting the 'R_GOOGLE_CHART_CACHE' environment variable, and can store the path in '.Renviron' for use in future R sessions if requested.
library(package = "gchartsmap") # set the cache path to a temp folder gchartsmap::gchart_set_cache(path = tempdir()) # save the cache path in a temporary folder # if you want to save the cache path in your default .Renviron, # use the default for path gchartsmap::gchart_set_cache( install = TRUE, path = tempdir(), overwrite = TRUE, home = tempdir() ) # clean up list.files( tempdir(), all.files = TRUE, full.names = TRUE, pattern = ".Renv" ) |> unlink()library(package = "gchartsmap") # set the cache path to a temp folder gchartsmap::gchart_set_cache(path = tempdir()) # save the cache path in a temporary folder # if you want to save the cache path in your default .Renviron, # use the default for path gchartsmap::gchart_set_cache( install = TRUE, path = tempdir(), overwrite = TRUE, home = tempdir() ) # clean up list.files( tempdir(), all.files = TRUE, full.names = TRUE, pattern = ".Renv" ) |> unlink()