knitr::opts_chunk$set(echo = TRUE)
library(rnaturalearth) library(sf)
This is our base layer, Australia, of the map from Naturalearth.com.
oz <- ne_states(geounit = "australia", returnclass = "sf") plot(oz)
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)
usethis::use_data(oz_label, overwrite = TRUE) usethis::use_data(oz_outline, overwrite = TRUE)
sessioninfo::session_info()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.