-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME.qmd
More file actions
318 lines (255 loc) · 8.25 KB
/
README.qmd
File metadata and controls
318 lines (255 loc) · 8.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
---
format: gfm
default-image-extension: ''
knitr:
opts_chunk:
collapse: true
comment: "#>"
warning: false
message: false
dev: "ragg_png"
tidy: "styler"
fig.path: "man/figures/README-"
dpi: 150
out.width: "100%"
---
<!-- README.md is generated from README.qmd. Please edit that file -->
# giscoR <a href="https://ropengov.github.io/giscoR/"><img src="man/figures/logo.png" alt="giscoR website" align="right" height="139"/></a>
<!-- badges: start -->
[](https://ropengov.org/)
[](https://CRAN.R-project.org/package=giscoR)
[](https://cran.r-project.org/web/checks/check_results_giscoR.html)
[](https://CRAN.R-project.org/package=giscoR)
[](https://ropengov.r-universe.dev/giscoR)
[](https://github.com/rOpenGov/giscoR/actions/workflows/check-full.yaml)
[](https://app.codecov.io/gh/ropengov/giscoR)
[](https://www.codefactor.io/repository/github/ropengov/giscor)
[](https://doi.org/10.32614/CRAN.package.giscoR)
[](https://www.repostatus.org/#active)
<!-- badges: end -->
[**giscoR**](https://ropengov.github.io/giscoR//) is an **R** package that
provides a simple interface to [GISCO](https://ec.europa.eu/eurostat/web/gisco)
data from Eurostat. It allows you to download and work with global and European
geospatial datasets (such as country boundaries, NUTS regions, coastlines, and
labels) directly in **R**.
## Key features
- Retrieve **GISCO files** for countries, regions, and administrative units.
- Access data at multiple resolutions: `60M`, `20M`, `10M`, `03M`, `01M`.
- Choose from three projections: **EPSG 4326**, **3035**, or **3857**.
- Works seamlessly with **sf** objects for spatial analysis.
- Includes **caching** for faster repeated access.
## Installation
::: pkgdown-release
Install **giscoR** from [**CRAN**](https://CRAN.R-project.org/package=giscoR):
```{r}
#| eval: false
install.packages("giscoR")
```
:::
::: pkgdown-devel
Check the docs of the developing version in
<https://ropengov.github.io/giscoR/dev/>.
You can install the development version of **giscoR** with:
```{r}
#| eval: false
# install.packages("pak")
pak::pak("rOpenGov/giscoR")
```
Alternatively, you can install **giscoR** via
[r-universe](https://ropengov.r-universe.dev/giscoR):
```{r}
#| eval: false
install.packages(
"giscoR",
repos = c("https://ropengov.r-universe.dev", "https://cloud.r-project.org")
)
```
:::
## Quick example
This script highlights some features of **giscoR** :
```{r}
#| label: resolution-map
#| fig-cap: The Netherlands boundaries at different resolutions
library(giscoR)
library(sf)
library(dplyr)
# Download The Netherlands boundaries at different resolutions
nl_all <- lapply(c("60", "20", "10", "03"), function(r) {
gisco_get_countries(country = "Netherlands", year = 2024, resolution = r) |>
mutate(res = paste0(r, "M"))
}) |>
bind_rows()
glimpse(nl_all)
# Plot with ggplot2
library(ggplot2)
ggplot(nl_all) +
geom_sf(fill = "#AD1D25") +
facet_wrap(~res) +
labs(
title = "The Netherlands boundaries at different resolutions",
subtitle = "Year: 2024",
caption = gisco_attributions()
) +
theme_minimal()
```
## Advanced example: Thematic maps
This example shows a thematic map created with the **ggplot2** package. The data
are obtained via the **eurostat** package. This follows the work of [Milos
Popovic](https://milospopovic.net/).
We start by extracting the corresponding geographic data:
```{r}
#| label: euroex
#| fig-asp: 1.1
library(giscoR)
library(dplyr)
library(eurostat)
library(ggplot2)
# Get sf objects
nuts3 <- gisco_get_nuts(
year = 2021,
epsg = 3035,
resolution = 10,
nuts_level = 3
)
# Get country lines (NUTS 0 level)
country_lines <- gisco_get_nuts(
year = 2021,
epsg = 3035,
resolution = 10,
spatialtype = "BN",
nuts_level = 0
)
```
We now download the data from Eurostat:
```{r}
# Use eurostat
popdens <- get_eurostat("demo_r_d3dens") |>
filter(TIME_PERIOD == "2021-01-01")
```
Finally, we merge and manipulate the data to create the final plot:
```{r}
#| label: thematic-map
#| fig-asp: 1.1
#| fig-cap: Population density in 2021
# Merge data
nuts3_sf <- nuts3 |>
left_join(popdens, by = "geo")
# Breaks and labels
br <- c(0, 25, 50, 100, 200, 500, 1000, 2500, 5000, 10000, 30000)
labs <- prettyNum(br[-1], big.mark = ",")
# Label function used in the plot, mainly for NAs
labeller_plot <- function(x) {
ifelse(is.na(x), "No Data", x)
}
nuts3_sf <- nuts3_sf |>
# Cut with labels
mutate(values_cut = cut(values, br, labels = labs))
# Palette
pal <- hcl.colors(length(labs), "Lajolla")
# Plot
ggplot(nuts3_sf) +
geom_sf(aes(fill = values_cut), linewidth = 0, color = NA, alpha = 0.9) +
geom_sf(data = country_lines, col = "black", linewidth = 0.1) +
# Center in Europe: EPSG 3035
coord_sf(
xlim = c(2377294, 7453440),
ylim = c(1313597, 5628510)
) +
# Legends
scale_fill_manual(
values = pal,
# Label for NA
labels = labeller_plot,
drop = FALSE,
guide = guide_legend(direction = "horizontal", nrow = 1)
) +
# Theming
theme_void() +
# Theme
theme(
plot.title = element_text(
color = rev(pal)[2],
size = rel(1.5),
hjust = 0.5,
vjust = -6
),
plot.subtitle = element_text(
color = rev(pal)[2],
size = rel(1.25),
hjust = 0.5,
vjust = -10,
face = "bold"
),
plot.caption = element_text(color = "grey60", hjust = 0.5, vjust = 0),
legend.text = element_text(color = "grey20", hjust = .5),
legend.title = element_text(color = "grey20", hjust = .5),
legend.position = "bottom",
legend.title.position = "top",
legend.text.position = "bottom",
legend.key.height = unit(.5, "line"),
legend.key.width = unit(2.5, "line")
) +
# Annotate and labs
labs(
title = "Population density in 2021",
subtitle = "NUTS-3 level",
fill = "people per sq. kilometer",
caption = paste0(
"Source: Eurostat, ",
gisco_attributions(),
"\nBased on Milos Popovic's work"
)
)
```
## Caching
Large datasets (e.g., LAU or high-resolution files) can exceed 50MB. Use:
```{r}
#| eval: false
gisco_set_cache_dir("./path/to/location")
```
Files will be stored locally for faster access.
## Contribute
Check the GitHub page for [source code](https://github.com/rOpenGov/giscoR/).
Contributions are welcome:
- [Use issue tracker](https://github.com/rOpenGov/giscoR/issues) for feedback
and bug reports.
- [Send pull requests](https://github.com/rOpenGov/giscoR/)
- [Star us on the GitHub page](https://github.com/rOpenGov/giscoR)
## Citation
```{r}
#| echo: false
#| results: asis
print(citation("giscoR"), bibtex = FALSE)
```
A BibTeX entry for LaTeX users is
```{r}
#| echo: false
#| comment: ''
toBibtex(citation("giscoR"))
```
## General copyright
<figure>
<blockquote class="blockquote">
[Eurostat's general copyright notice and licence
policy](https://ec.europa.eu/eurostat/web/main/help/copyright-notice) applies.
Moreover, there are specific rules that apply to some of the following datasets
available for downloading. The download and use of these data are subject to
these rules being accepted. See our [administrative
units](https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units) and
[statistical
units](https://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units) for
more details.
</blockquote>
```{=html}
<figcaption class="blockquote-footer">Source:
<cite title="GISCO"><https://ec.europa.eu/eurostat/web/gisco/geodata></cite>
</figcaption>
```
</figure>
## Disclaimer
This package is neither affiliated with nor endorsed by Eurostat. The authors
are not responsible for any misuse of the data.