/
what-is-a-country.Rmd
169 lines (108 loc) · 4.35 KB
/
what-is-a-country.Rmd
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
---
title: "What is a country ?"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{What is a country ?}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
This vignette shows how [rnaturalearth](https://github.com/ropensci/rnaturalearth) allows mapping countries using different definitions of what a country is. What a country is can be more complicated than you might expect.
For example, from my own parochial perspective, it allows mapping the UK as a whole or separating out England, Scotland, Wales and Northern Ireland. It also allows you to exclude far away places like the Falkland Islands, or not. Mapping France it allows the inclusion or exclusion of French Guiana and islands in the South Pacific.
[rnaturalearth](https://github.com/ropensci/rnaturalearth) is an R package to hold and facilitate interaction with natural earth vector map data.
[Natural Earth](https://www.naturalearthdata.com/) is a public domain map dataset including vector country boundaries.
This vignette uses `plot` as a simple, quick way to plot the data obtained using `rnaturalearth`. `rnaturalearth` data can also be used to make more elaborate maps with `ggplot2`, `tmap` and other options.
## Load required packages
```r
library(rnaturalearth)
```
## Country types : countries, map_units and sovereignty
Natural Earth data are classified by `countries`, `map_units` and `sovereignty`. Below you will see that specifying `united kingdom` for
- `countries` gives the UK undivided
- `map_units` gives England, Scotland, Wales and Northern Ireland
- `sovereignty` includes the Falkland Islands
Filtering by `geounit` can give finer control, e.g. to plot Scotland alone, or France without French Guiana.
```r
# countries, UK undivided
plot(ne_countries(country = "united kingdom", type = "countries")["geometry"])
```
![](what-is-a-country.Rmd-3-1.png)
```r
# map_units, UK divided into England, Scotland, Wales and Northern Ireland
plot(ne_countries(country = "united kingdom", type = "map_units")["geometry"])
```
![](what-is-a-country.Rmd-3-2.png)
```r
# map_units, select by geounit to plot Scotland alone
plot(ne_countries(geounit = "scotland", type = "map_units")["geometry"])
```
![](what-is-a-country.Rmd-3-3.png)
```r
# sovereignty, Falkland Islands included in UK
plot(ne_countries(country = "united kingdom", type = "sovereignty")["geometry"], col = "red")
plot(ne_coastline(scale = 110)["geometry"], lty = 3, add = TRUE)
```
![](what-is-a-country.Rmd-3-4.png)
```r
# France, country includes French Guiana
plot(ne_countries(country = "france")["geometry"])
# France map_units includes French Guiana too
plot(ne_countries(country = "france", type = "map_units")["geometry"])
```
![](what-is-a-country.Rmd-3-5.png)
```r
# France filter map_units by geounit to exclude French Guiana
plot(ne_countries(geounit = "france", type = "map_units")["geometry"])
```
![](what-is-a-country.Rmd-3-6.png)
```r
# France sovereignty includes South Pacicic islands
plot(ne_countries(country = "france", type = "sovereignty")["geometry"], col = "red")
plot(ne_coastline(scale = 110)["geometry"], lty = 3, add = TRUE)
```
![](what-is-a-country.Rmd-3-7.png)
## Country scales : small, medium and large
The different definitions of a country outlined above are available at different scales.
```r
plot(
ne_countries(country = "united kingdom", scale = "large")["geometry"],
main = "large scale"
)
```
![](what-is-a-country.Rmd-4-1.png)
```r
# countries, medium scale
plot(
ne_countries(country = "united kingdom", scale = "medium")["geometry"],
main = "medium scale"
)
```
![](what-is-a-country.Rmd-4-2.png)
```r
# countries, small scale
plot(
ne_countries(country = "united kingdom", scale = "small")["geometry"],
main = "small scale"
)
```
![](what-is-a-country.Rmd-4-3.png)
## States, admin level 1, select by country or geounit
```r
# states country='united kingdom'
plot(ne_states(country = "united kingdom")["geometry"])
```
![](what-is-a-country.Rmd-5-1.png)
```r
# states geounit='england'
plot(ne_states(geounit = "england")["geometry"])
```
![](what-is-a-country.Rmd-5-2.png)
```r
# states country='france'
plot(ne_states(country = "france")["geometry"])
```
![](what-is-a-country.Rmd-5-3.png)
```r
# states geounit='france'
plot(ne_states(geounit = "france")["geometry"])
```
![](what-is-a-country.Rmd-5-4.png)