knitr::opts_chunk$set(echo = TRUE)

Load Libraries

library(rnaturalearth)
library(sf)

Get the Data to Create Our Map

Add a Shapefile of Australia

This is our base layer, Australia, of the map from Naturalearth.com.

oz <- ne_states(geounit = "australia", returnclass = "sf")

plot(oz)

Crop and Reproject

However, for the data that this package is intended for use with, only New South Wales and Queensland are necessary.

Also for cartography purposes, we will reproject the map to Australian Albers for A.C.T., N.S.W and Qld.

Two objects are created, one oz_label for state outlines and labels and the other, oz_outline for a basic country outline to use over the top of oz_label.

bound <- raster::extent(131,
                        155,
                        -39,
                        -10)

oz_label <- sf::st_intersection(oz,
                             sf::st_set_crs(
                               sf::st_as_sf(
                                 as(bound,
                                    "SpatialPolygons")),
                               sf::st_crs(oz))) %>%
  sf::st_transform(crs = 3577)

oz_label <-
  oz_label %>%
  dplyr::mutate(
    CENTROID = purrr::map(geometry, sf::st_centroid),
    COORDS = purrr::map(CENTROID, sf::st_coordinates),
    COORDS_X = purrr::map_dbl(COORDS, 1),
    COORDS_Y = purrr::map_dbl(COORDS, 2)
  )

oz_label$nudge_x <- 0
oz_label$nudge_y <- 0

oz_outline <-
  oz %>%
  dplyr::group_by(admin) %>%
  dplyr::summarize() %>%
  sf::st_intersection(
    sf::st_set_crs(
      sf::st_as_sf(
        as(bound,
           "SpatialPolygons")),
      sf::st_crs(oz))) %>%
  sf::st_transform(crs = 3577)

plot(oz_label)

plot(oz_outline)

Save Data for Use as Base Map

usethis::use_data(oz_label, overwrite = TRUE)
usethis::use_data(oz_outline, overwrite = TRUE)

R System Information

sessioninfo::session_info()


adamhsparks/fulcrum documentation built on Nov. 19, 2019, 4:49 a.m.