Skip to content

Commit 85295cf

Browse files
committed
Use modern pipe in vignette
1 parent 410d54d commit 85295cf

File tree

1 file changed

+64
-28
lines changed

1 file changed

+64
-28
lines changed

vignettes/ggautomap.Rmd

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ All of the summary geoms of `ggautomap` can then be used to draw your data.
4444
## Scatter
4545

4646
```{r scatter, fig.height = 3, fig.width = 7}
47-
covid_cases_nsw %>%
47+
covid_cases_nsw |>
4848
ggplot(aes(location = lga)) +
4949
geom_boundaries(feature_type = "nswgeo.lga") +
5050
geom_geoscatter(aes(colour = type), sample_type = "random", size = 0.5) +
51-
coord_automap(feature_type = "nswgeo.lga", xlim = c(147, 153), ylim = c(-33.7, -29)) +
51+
coord_automap(
52+
feature_type = "nswgeo.lga",
53+
xlim = c(147, 153),
54+
ylim = c(-33.7, -29)
55+
) +
5256
guides(colour = guide_legend(override.aes = list(size = 1))) +
5357
theme_void()
5458
```
@@ -63,15 +67,21 @@ provide it to each relevant geom. The geoms in this package are all inset-aware.
6367
See `{ggmapinset}` for details.
6468

6569
```{r inset, fig.height = 3, fig.width = 7}
66-
covid_cases_nsw %>%
70+
covid_cases_nsw |>
6771
ggplot(aes(location = lga)) +
6872
geom_boundaries(feature_type = "nswgeo.lga") +
6973
geom_geoscatter(aes(colour = type), size = 0.5) +
7074
geom_inset_frame() +
71-
coord_automap(feature_type = "nswgeo.lga", inset = configure_inset(
72-
centre = "Blacktown", radius = 40, units = "km",
73-
scale = 7, translation = c(400, -100)
74-
)) +
75+
coord_automap(
76+
feature_type = "nswgeo.lga",
77+
inset = configure_inset(
78+
centre = "Blacktown",
79+
radius = 40,
80+
units = "km",
81+
scale = 7,
82+
translation = c(400, -100)
83+
)
84+
) +
7585
theme_void()
7686
```
7787

@@ -82,8 +92,8 @@ packed circle in the centre of each feature. It also shows how you can
8292
fine-tune the plot with the usual `{ggplot2}` functions.
8393

8494
```{r packed, fig.height = 3, fig.width = 7}
85-
covid_cases_nsw %>%
86-
dplyr::filter(year >= 2021) %>%
95+
covid_cases_nsw |>
96+
dplyr::filter(year >= 2021) |>
8797
ggplot(aes(location = lhd)) +
8898
geom_boundaries(feature_type = "nswgeo.lhd") +
8999
geom_centroids(aes(colour = type), position = position_circle_repel_sf(scale = 35), size = 1) +
@@ -106,7 +116,7 @@ the rows are disease cases) then you can use `geom_choropleth()` to aggregate th
106116
into counts.
107117

108118
```{r choro-long, fig.height = 3, fig.width = 7}
109-
covid_cases_nsw %>%
119+
covid_cases_nsw |>
110120
ggplot(aes(location = lhd)) +
111121
geom_choropleth() +
112122
geom_boundaries(
@@ -128,22 +138,36 @@ existing column that you'd like to map to the `fill` aesthetic, then instead use
128138

129139
```{r choro-wide, fig.height = 3, fig.width = 7}
130140
summarised_data <- data.frame(
131-
lhd = c("Western Sydney", "Sydney", "Far West", "Mid North Coast", "South Western Sydney"),
141+
lhd = c(
142+
"Western Sydney",
143+
"Sydney",
144+
"Far West",
145+
"Mid North Coast",
146+
"South Western Sydney"
147+
),
132148
cases = c(250, 80, 20, NA, 100)
133149
)
134150
135-
summarised_data %>%
151+
summarised_data |>
136152
ggplot(aes(location = lhd)) +
137153
geom_sf_inset(aes(fill = cases), stat = "automap", colour = NA) +
138154
geom_boundaries(
139-
feature_type = "nswgeo.lhd", colour = "black", linewidth = 0.1,
155+
feature_type = "nswgeo.lhd",
156+
colour = "black",
157+
linewidth = 0.1,
140158
outline.aes = list(colour = NA)
141159
) +
142160
geom_inset_frame() +
143-
coord_automap(feature_type = "nswgeo.lhd", inset = configure_inset(
144-
centre = "Western Sydney", radius = 60, units = "km",
145-
scale = 3.5, translation = c(350, 0)
146-
)) +
161+
coord_automap(
162+
feature_type = "nswgeo.lhd",
163+
inset = configure_inset(
164+
centre = "Western Sydney",
165+
radius = 60,
166+
units = "km",
167+
scale = 3.5,
168+
translation = c(350, 0)
169+
)
170+
) +
147171
scale_fill_gradient(low = "#e6f9ff", high = "#00394d", na.value = "grey90") +
148172
theme_void()
149173
```
@@ -154,7 +178,7 @@ summarised_data %>%
154178
These examples give some different ways of placing text, accounting for possible insets.
155179

156180
```{r text-inset, fig.height = 3, fig.width = 7}
157-
covid_cases_nsw %>%
181+
covid_cases_nsw |>
158182
ggplot(aes(location = lhd)) +
159183
geom_choropleth() +
160184
geom_boundaries(feature_type = "nswgeo.lhd") +
@@ -181,7 +205,7 @@ often doesn't make sense in mapping contexts.
181205
library(ggrepel)
182206
183207
# label all features that have data
184-
covid_cases_nsw %>%
208+
covid_cases_nsw |>
185209
ggplot(aes(location = lhd)) +
186210
geom_choropleth() +
187211
geom_boundaries(feature_type = "nswgeo.lhd") +
@@ -199,15 +223,21 @@ covid_cases_nsw %>%
199223
data = ~ dplyr::slice_head(.x, by = lhd)
200224
) +
201225
scale_fill_distiller(direction = 1) +
202-
coord_automap(feature_type = "nswgeo.lhd", inset = configure_inset(
203-
centre = "Western Sydney", radius = 60, units = "km",
204-
scale = 3.5, translation = c(350, 0)
205-
)) +
226+
coord_automap(
227+
feature_type = "nswgeo.lhd",
228+
inset = configure_inset(
229+
centre = "Western Sydney",
230+
radius = 60,
231+
units = "km",
232+
scale = 3.5,
233+
translation = c(350, 0)
234+
)
235+
) +
206236
labs(x = NULL, y = NULL) +
207237
theme_void()
208238
209239
# label all features in the map regardless of data, hiding visually overlapping labels
210-
covid_cases_nsw %>%
240+
covid_cases_nsw |>
211241
ggplot(aes(location = lhd)) +
212242
geom_choropleth() +
213243
geom_boundaries(feature_type = "nswgeo.lhd") +
@@ -225,10 +255,16 @@ covid_cases_nsw %>%
225255
inherit.aes = FALSE
226256
) +
227257
scale_fill_distiller(direction = 1, palette = 2) +
228-
coord_automap(feature_type = "nswgeo.lhd", inset = configure_inset(
229-
centre = "Western Sydney", radius = 60, units = "km",
230-
scale = 4, translation = c(500, 0)
231-
)) +
258+
coord_automap(
259+
feature_type = "nswgeo.lhd",
260+
inset = configure_inset(
261+
centre = "Western Sydney",
262+
radius = 60,
263+
units = "km",
264+
scale = 4,
265+
translation = c(500, 0)
266+
)
267+
) +
232268
labs(x = NULL, y = NULL) +
233269
theme_void()
234270
```

0 commit comments

Comments
 (0)