-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
128 lines (85 loc) · 3.25 KB
/
Copy pathREADME.Rmd
File metadata and controls
128 lines (85 loc) · 3.25 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r}
#| echo: false
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# gchartsmap: Access 'Google Charts' Map Data
<!-- badges: start -->
[](https://github.com/odeleongt/gchartsmap/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/odeleongt/gchartsmap)
<!-- badges: end -->
## Overview
This package connects to the 'Google Charts' geographic data resources, allowing
the user to download contents to use as a reference for related services like
'Google Trends'.
## Installation
Install the package from CRAN using:
```{r eval=FALSE}
install.packages("gchartsmap")
```
Install the development version from GitHub using:
```{r eval=FALSE}
remotes::install_github("odeleongt/gchartsmap")
```
## Usage
You will need Internet access to download data from the Google Charts static
content servers.
There is some documentation for developers using Google Charts at
<https://developers.google.com/chart/interactive/docs/gallery/geochart>, but no
information is provided on how to access the data directly.
Geographic information for regions at the sub-national level can be accessed
using the country codes listed in the Google Charts documentation, with some
suffix that is tracked in this package.
There is an additional level of data for the US that documents groups of counties,
and is used by services such as [Google Trends](https://trends.google.com/trends/),
but no documentation is provided for this.
Those files are accessed with an integer, and this package attempts to grab each
area by trying with numbers `1:1000` by default.
```{r}
#| label: setup
#| eval: FALSE
library(package = "gchartsmap")
library(package = "sf")
# use the default, or set your own cache path
gchart_set_cache("your/preferred/cache/path")
```
```{r}
#| echo: false
library(package = "gchartsmap")
library(package = "sf")
gchart_set_cache(tempdir())
```
A cache is needed, as we want to avoid constantly fetching files from the Google
static servers.
```{r results='hide'}
# check out a list of all country codes
all_countries <- gchart_countries()
# get data for the US
us <- gchart_generate_countries("US")
# check out some US areas
some_areas <- c(
503L, 507L, 520L, 522L, 524L, 525L, 530L, 561L, 567L, 575L,
606L, 630L, 656L, 691L
)
areas <- gchart_generate_us_areas(some_areas)
# make a simple map of Georgia, US
plot( sf::st_geometry(us[us$id == "US-GA",]), lwd = 3, border = "blue")
# draw the underlying areas
plot(areas[, "id"], axes = TRUE)
plot(sf::st_geometry(us[us$id == "US-GA",]), add = TRUE, lwd = 3, border = "blue")
```
These geographic data are only intended for simple presentation. As Google does
not provide documentation on the coordinate reference system, don't expect the
data to align to real world features without processing that is out of the scope
of this package.
In the plot above, you can notice some misalignment between the state border and
the smaller areas.