Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions vignettes/ggautomap.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,47 @@
labs(x = NULL, y = NULL) +
theme_void()
```

## Loading custom shape files

Before proceeding to load custom shape files, check the R package [rnaturalearth](https://github.com/ropensci/rnaturalearth) which contains maps for world maps and countries.

A shape file (`.shp`) is required, for example the Australian specific maps can be retrieved from [ABS Digital boundary files](https://www.abs.gov.au/statistics/standards/australian-statistical-geography-standard-asgs-edition-3/jul2021-jun2026/access-and-downloads/digital-boundary-files).

First read in the shape file using the `sf` package:

```{r, eval=FALSE}
sf <- st_read(map_files)
```
Shape files can be subset in a similar fashion to data.frames using `dplyr`:

```{r, eval=FALSE}
# subset to only include Victorian postcodes only
sf_vic <- sf::st_read(map_files) %>%
mutate(postcode = as.integer(POA_CODE21)) %>%

Check warning on line 252 in vignettes/ggautomap.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/ggautomap.Rmd,line=252,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces.
filter(POA_CODE21 >= 3000 & POA_CODE21 <= 3999)
```

After reading in the shape file, register with `cartographer` package:
```{r, eval=FALSE}
cartographer::register_map(
"sf.vic", # the map name

Check warning on line 259 in vignettes/ggautomap.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/ggautomap.Rmd,line=259,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces.
data = sf_vic, # this is the object we subsetted above
feature_column = "postcode", # data column to include
)
```

Check the map has been registered:
```{r, eval=FALSE}
> cartographer::feature_types()

Check warning on line 267 in vignettes/ggautomap.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/ggautomap.Rmd,line=267,col=1,[error] unexpected '>'
[1] "maps.italy" "rnaturalearth.countries_hires" "sf.vic" "maps.lakes"

Check warning on line 268 in vignettes/ggautomap.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/ggautomap.Rmd,line=268,col=114,[trailing_whitespace_linter] Remove trailing whitespace.

Check warning on line 268 in vignettes/ggautomap.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/ggautomap.Rmd,line=268,col=1,[indentation_linter] Indentation should be 0 spaces but is 1 spaces.
[5] "rnaturalearth.countries" "rnaturalearth.australia" "maps.nz" "maps.world"

Check warning on line 269 in vignettes/ggautomap.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/ggautomap.Rmd,line=269,col=114,[trailing_whitespace_linter] Remove trailing whitespace.
[9] "maps.state" "sf.nc" "maps.france"

Check warning on line 270 in vignettes/ggautomap.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/ggautomap.Rmd,line=270,col=83,[trailing_whitespace_linter] Remove trailing whitespace.
```

To use the registered shapefile:
```{r, eval=FALSE}
...
geom_boundaries(feature_type = "sf.vic") +

Check warning on line 276 in vignettes/ggautomap.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/ggautomap.Rmd,line=276,col=2,[indentation_linter] Indentation should be 0 spaces but is 2 spaces.
...
```
Loading