###############################################################################
#' An Alaska Map Function (Robinson, labeled)
#'
#' These functions create base maps of Alaska inclusive of NMFS Reporting Areas, showing Canadian and Russian shorelines.
#' The functions utilize a shape file that is contained in the JAC tools package (default) that was originally generated by J.Gasper (AKRO, April 2021).
#' Alternative shape files can be used by specifing a path and file name to the boundary shape file (.shp). \cr
#' @details
#' Note that the warning message:
#' \emph{Warning message: In st_centroid.sf(nmfs_areas_shapefile): st_centroid assumes attributes are constant over geometries of x} \cr
#' Indicates that the lables are not located exactly on the centroid for the NMFS Reporting Area (in addition some were intentially moved). \cr
#' Additionally note the message \emph{"although coordinates are longitude/latitude, st_intersection assumes that they are planar" }
#' indicates that spatial coordinates are on a flat space ({\eqn{R^2}}, not an ellipsoid or sphere on {\eqn{S^2}}). Package s2 is not in use. \cr
#' See also sf package: <https://cran.r-project.org/web/packages/sf/index.html> and s2 package <https://cran.r-project.org/web/packages/s2/index.html> \cr
#'
#' There are 5 maps contained in the JACtools package:\itemize{\item 2 Mercator with NMFS Reporting Areas (with and without labels: AK_MercatorL_fxn, AK_Mercator_fxn)
#' \item 2 Robinson with NMFS Reporting Areas (with and without labels: AK_RobinsonL_fxn, AK_Robinson_fxn)
#' \item 1 Mercator without NMFS Reporting Areas (AKMap_fxn)}
#' <https://www.icsm.gov.au/education/fundamentals-mapping/projections/commonly-used-map-projections>
#'
#' @keywords AK map NMFS_Area
#' @export
#' @examples
#' AK_RobinsonL_fxn()
AK_RobinsonL_fxn <- function(Path = 'internal', ShapeFileName = 'internal', label.size = 3){
theme_set(theme_bw())
if(Path != 'internal') nmfs_areas_shapefile <- sf::st_read(paste0(Path, ShapeFileName))
if(Path != 'internal') alaska_shapefile <- sf::st_read(paste0(Path, ShapeFileName))
areas_2 <- cbind(nmfs_areas_shapefile, sf::st_coordinates(sf::st_centroid(nmfs_areas_shapefile)))
areas_2$nudge_y <- 0
areas_2$nudge_y[areas_2$REP_AREA == "541"] <- -10000
areas_2$nudge_y[areas_2$REP_AREA == "542"] <- -70000
areas_2$nudge_x <- 0
areas_2$nudge_x[areas_2$REP_AREA == "514"] <- -70000
(ggAlaska <- ggplot2::ggplot() +
theme(legend.position = "none",
panel.grid.minor = element_line(colour = "grey50")
) +
geom_sf(data = alaska_shapefile, aes(fill = ID)) +
geom_sf(data = areas_2, fill=NA, color='grey50') +
geom_text(data = areas_2, aes(X, Y, label = REP_AREA), size = label.size,
nudge_y = areas_2$nudge_y, nudge_x = areas_2$nudge_x) +
xlab('') + ylab('')
)
}
###############################################################################
#' An Alaska Map Function (Robinson, unlabeled)
#'
#' This function creates a base map of Alaska inclusive of NMFS Reporting Areas, showing Canadian and Russian shorelines.
#' This function utilizes a shape file that is contained in the JAC tools package (default) that was originally generated by J.Gasper (AKRO, April 2021).
#' Alternative shape files can be used by specifing a path and file name to the boundary shape file (.shp). \cr
#' @details
#' Note that the warning message:
#' \emph{Warning message: In st_centroid.sf(nmfs_areas_shapefile): st_centroid assumes attributes are constant over geometries of x} \cr
#' Indicates that the lables are not located exactly on the centroid for the NMFS Reporting Area (in addition some were intentially moved). \cr
#' Additionally note the message \emph{"although coordinates are longitude/latitude, st_intersection assumes that they are planar" }
#' indicates that spatial coordinates are on a flat space ({\eqn{R^2}}, not an ellipsoid or sphere on {\eqn{S^2}}). Package s2 is not in use. \cr
#' See also sf package: <https://cran.r-project.org/web/packages/sf/index.html> and s2 package <https://cran.r-project.org/web/packages/s2/index.html> \cr
#'
#' There are 5 maps contained in the JACtools package:\itemize{\item 2 Mercator with NMFS Reporting Areas (with and without labels: AK_MercatorL_fxn, AK_Mercator_fxn)
#' \item 2 Robinson with NMFS Reporting Areas (with and without labels: AK_RobinsonL_fxn, AK_Robinson_fxn)
#' \item 1 Mercator without NMFS Reporting Areas (AKMap_fxn)}
#' (https://www.icsm.gov.au/education/fundamentals-mapping/projections/commonly-used-map-projections)
#'
#' @keywords AK map NMFS_Area
#' @export
#' @examples
#' AK_Robinson_fxn()
AK_Robinson_fxn <- function(Path = 'internal', ShapeFileName = 'internal'){
theme_set(theme_bw())
if(Path != 'internal') nmfs_areas_shapefile <- sf::st_read(paste0(Path, ShapeFileName))
if(Path != 'internal') alaska_shapefile <- sf::st_read(paste0(Path, ShapeFileName))
areas_2 <- cbind(nmfs_areas_shapefile, sf::st_coordinates(sf::st_centroid(nmfs_areas_shapefile)))
areas_2$nudge_y <- 0
areas_2$nudge_y[areas_2$REP_AREA == "541"] <- -10000
areas_2$nudge_y[areas_2$REP_AREA == "542"] <- -70000
areas_2$nudge_x <- 0
areas_2$nudge_x[areas_2$REP_AREA == "514"] <- -70000
(ggAlaska <- ggplot2::ggplot() +
theme(legend.position = "none",
panel.grid.minor = element_line(colour = "grey50")
) +
geom_sf(data = alaska_shapefile, aes(fill = ID)) +
geom_sf(data = areas_2, fill=NA, color='grey50') +
xlab('') + ylab('')
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.