Skip to content

Commit 320e96f

Browse files
committed
Use new inset shape helpers
1 parent 85295cf commit 320e96f

File tree

8 files changed

+102
-130
lines changed

8 files changed

+102
-130
lines changed

DESCRIPTION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Imports:
2727
cartographer (>= 0.2),
2828
cli (>= 3.4.0),
2929
dplyr (>= 1.0.0),
30-
ggmapinset (>= 0.3),
30+
ggmapinset (> 0.4.0),
3131
ggplot2 (>= 3.4.2),
3232
packcircles (>= 0.3.4),
3333
rlang (>= 1.0.0),
@@ -39,7 +39,6 @@ Collate:
3939
'stat_automap.R'
4040
'stat_automap_coords.R'
4141
'choropleth.R'
42-
'configure_inset.R'
4342
'coord_automap.R'
4443
'crs.R'
4544
'geom_boundaries.R'

NAMESPACE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method(coerce_centre,character)
34
export(GeomSfInset)
45
export(PositionCircleRepel)
56
export(PositionCircleRepelSf)
@@ -22,6 +23,9 @@ export(geom_sf_label_inset)
2223
export(geom_sf_text_inset)
2324
export(position_circle_repel)
2425
export(position_circle_repel_sf)
26+
export(shape_circle)
27+
export(shape_rectangle)
28+
export(shape_sf)
2529
export(stat_automap)
2630
export(stat_automap_coords)
2731
export(stat_choropleth)
@@ -33,10 +37,15 @@ import(vctrs)
3337
importFrom(ggmapinset,GeomSfInset)
3438
importFrom(ggmapinset,StatSfCoordinatesInset)
3539
importFrom(ggmapinset,StatSfInset)
40+
importFrom(ggmapinset,coerce_centre)
41+
importFrom(ggmapinset,configure_inset)
3642
importFrom(ggmapinset,geom_inset_frame)
3743
importFrom(ggmapinset,geom_sf_inset)
3844
importFrom(ggmapinset,geom_sf_label_inset)
3945
importFrom(ggmapinset,geom_sf_text_inset)
46+
importFrom(ggmapinset,shape_circle)
47+
importFrom(ggmapinset,shape_rectangle)
48+
importFrom(ggmapinset,shape_sf)
4049
importFrom(ggmapinset,stat_sf_inset)
4150
importFrom(packcircles,circleRepelLayout)
4251
importFrom(rlang,.data)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ggautomap (development version)
22

3+
* Updated to use new inset shape definition style from {ggmapinset}.
4+
There is no longer a need to override the `configure_inset()` function
5+
which was brittle and depended on order of package attachment to work.
6+
37
# ggautomap 0.3.3
48

59
* Doc tweaks and housekeeping.

R/aaa.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,32 @@ ggmapinset::geom_sf_text_inset
3434
#' @importFrom ggmapinset geom_sf_label_inset
3535
#' @export
3636
ggmapinset::geom_sf_label_inset
37+
38+
#' @importFrom ggmapinset configure_inset
39+
#' @export
40+
ggmapinset::configure_inset
41+
42+
#' @importFrom ggmapinset shape_circle
43+
#' @export
44+
ggmapinset::shape_circle
45+
46+
#' @importFrom ggmapinset shape_rectangle
47+
#' @export
48+
ggmapinset::shape_rectangle
49+
50+
#' @importFrom ggmapinset shape_sf
51+
#' @export
52+
ggmapinset::shape_sf
53+
54+
#' @importFrom ggmapinset coerce_centre
55+
#' @export
56+
coerce_centre.character <- function(centre, feature_type = NA) {
57+
feature_type <- cartographer::resolve_feature_type(feature_type, centre)
58+
geom <- cartographer::map_sfc(centre, feature_type)
59+
crs_orig <- sf::st_crs(geom)
60+
61+
crs_working <- crs_eqc_midpoint(feature_type)
62+
geom <- sf::st_transform(geom, crs_working)
63+
centre <- sf::st_transform(sf::st_centroid(geom), crs_orig)
64+
centre
65+
}

R/configure_inset.R

Lines changed: 0 additions & 53 deletions
This file was deleted.

man/configure_inset.Rd

Lines changed: 0 additions & 55 deletions
This file was deleted.

man/reexports.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/ggautomap.Rmd

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ covid_cases_nsw |>
7575
coord_automap(
7676
feature_type = "nswgeo.lga",
7777
inset = configure_inset(
78-
centre = "Blacktown",
79-
radius = 40,
78+
shape_circle(
79+
centre = "Blacktown",
80+
radius = 40
81+
),
8082
units = "km",
8183
scale = 7,
8284
translation = c(400, -100)
@@ -96,12 +98,25 @@ covid_cases_nsw |>
9698
dplyr::filter(year >= 2021) |>
9799
ggplot(aes(location = lhd)) +
98100
geom_boundaries(feature_type = "nswgeo.lhd") +
99-
geom_centroids(aes(colour = type), position = position_circle_repel_sf(scale = 35), size = 1) +
101+
geom_centroids(
102+
aes(colour = type),
103+
position = position_circle_repel_sf(scale = 35),
104+
size = 1
105+
) +
100106
geom_inset_frame() +
101-
coord_automap(feature_type = "nswgeo.lhd", inset = configure_inset(
102-
centre = "Sydney", radius = 80, units = "km", feature_type = "nswgeo.lhd",
103-
scale = 6, translation = c(650, -100)
104-
)) +
107+
coord_automap(
108+
feature_type = "nswgeo.lhd",
109+
inset = configure_inset(
110+
shape_circle(
111+
centre = "Sydney",
112+
radius = 80,
113+
feature_type = "nswgeo.lhd"
114+
),
115+
units = "km",
116+
scale = 6,
117+
translation = c(650, -100)
118+
)
119+
) +
105120
facet_wrap(vars(year)) +
106121
labs(x = NULL, y = NULL) +
107122
theme_void() +
@@ -124,9 +139,16 @@ covid_cases_nsw |>
124139
outline.aes = list(colour = NA)
125140
) +
126141
geom_inset_frame() +
127-
coord_automap(feature_type = "nswgeo.lhd", inset = configure_inset(
128-
centre = "Western Sydney", radius = 60, units = "km",
129-
scale = 5, translation = c(400, -100)
142+
coord_automap(
143+
feature_type = "nswgeo.lhd",
144+
inset = configure_inset(
145+
shape_circle(
146+
centre = "Western Sydney",
147+
radius = 60
148+
),
149+
units = "km",
150+
scale = 5,
151+
translation = c(400, -100)
130152
)) +
131153
scale_fill_steps(low = "#e6f9ff", high = "#00394d", n.breaks = 5, na.value = "white") +
132154
theme_void()
@@ -161,8 +183,10 @@ summarised_data |>
161183
coord_automap(
162184
feature_type = "nswgeo.lhd",
163185
inset = configure_inset(
164-
centre = "Western Sydney",
165-
radius = 60,
186+
shape_circle(
187+
centre = "Western Sydney",
188+
radius = 60,
189+
),
166190
units = "km",
167191
scale = 3.5,
168192
translation = c(350, 0)
@@ -187,9 +211,16 @@ covid_cases_nsw |>
187211
stat = "automap_coords",
188212
data = ~ dplyr::slice_head(.x, by = lhd)
189213
) +
190-
coord_automap(feature_type = "nswgeo.lhd", inset = configure_inset(
191-
centre = "Western Sydney", radius = 60, units = "km",
192-
scale = 3.5, translation = c(350, 0)
214+
coord_automap(
215+
feature_type = "nswgeo.lhd",
216+
inset = configure_inset(
217+
shape_circle(
218+
centre = "Western Sydney",
219+
radius = 60
220+
),
221+
units = "km",
222+
scale = 3.5,
223+
translation = c(350, 0)
193224
)) +
194225
labs(x = NULL, y = NULL) +
195226
theme_void()
@@ -226,8 +257,10 @@ covid_cases_nsw |>
226257
coord_automap(
227258
feature_type = "nswgeo.lhd",
228259
inset = configure_inset(
229-
centre = "Western Sydney",
230-
radius = 60,
260+
shape_circle(
261+
centre = "Western Sydney",
262+
radius = 60
263+
),
231264
units = "km",
232265
scale = 3.5,
233266
translation = c(350, 0)
@@ -258,8 +291,10 @@ covid_cases_nsw |>
258291
coord_automap(
259292
feature_type = "nswgeo.lhd",
260293
inset = configure_inset(
261-
centre = "Western Sydney",
262-
radius = 60,
294+
shape_circle(
295+
centre = "Western Sydney",
296+
radius = 60
297+
),
263298
units = "km",
264299
scale = 4,
265300
translation = c(500, 0)

0 commit comments

Comments
 (0)