###############################################################################
#' Alaska Map Functions (Mercator, labeled)
#'
#' @description
#' 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:\cr
#' \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_MercatorL_fxn()
AK_MercatorL_fxn <- function(Path = 'internal', ShapeFileName = 'internal', label.size){
theme_set(theme_bw())
sf::sf_use_s2(FALSE)
world2 <- sf::st_as_sf(maps::map('world2', plot = FALSE, fill = TRUE))
AK_cropped <- sf::st_crop(world2, xmin = 170, xmax = 230,
ymin = 50, ymax = 67)
if(Path != 'internal') nmfs_areas_shapefile <- sf::st_read(paste0(Path, ShapeFileName))
area_2 <- sf::st_transform(x = nmfs_areas_shapefile, crs = 4326, proj4string="+proj=longlat +datum=WGS84 +no_defs")
areas_shifted <- sf::st_shift_longitude(area_2)
areas_cropped <- sf::st_crop(areas_shifted, xmin = 170, xmax = 230,
ymin = 50, ymax = 67)
areas_cropped <- cbind(areas_cropped, sf::st_coordinates(sf::st_centroid(areas_cropped)))
areas_cropped$nudge_y <- 0
areas_cropped$nudge_y[areas_cropped$REP_AREA == "543"] <- -0.5
areas_cropped$nudge_y[areas_cropped$REP_AREA == "519"] <- 0.1
areas_cropped$nudge_x <- 0
areas_cropped$nudge_x[areas_cropped$REP_AREA == "514"] <- -1
(ggAlaska <- ggplot2::ggplot() +
theme(legend.position = "none",
panel.grid.minor = element_line(colour = "grey50")
) +
geom_sf(data = AK_cropped, aes(fill = ID)) +
scale_fill_manual(values=c('grey20','grey40','grey80')) +
geom_sf(data = areas_cropped,
fill=NA, color='grey50') +
scale_x_continuous(minor_breaks = seq(170, 230, 1)) +
guides(fill = guide_legend(legend.position = "none")) +
geom_text(data = areas_cropped, aes(X, Y, label = REP_AREA), size = label.size,
nudge_y = areas_cropped$nudge_y, nudge_x = areas_cropped$nudge_x) +
xlab('') + ylab('')
)
}
###############################################################################
#' Alaska Map Functions (Mercator, unlabeled)
#'
#' @description
#' 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_Mercator_fxn()
AK_Mercator_fxn <- function(Path = 'internal', ShapeFileName = 'internal'){
theme_set(theme_bw())
sf::sf_use_s2(FALSE)
world2 <- sf::st_as_sf(maps::map('world2', plot = FALSE, fill = TRUE))
AK_cropped <- sf::st_crop(world2, xmin = 170, xmax = 230,
ymin = 50, ymax = 67)
if(Path != 'internal') nmfs_areas_shapefile <- sf::st_read(paste0(Path, ShapeFileName))
area_2 <- sf::st_transform(x = nmfs_areas_shapefile, crs = 4326, proj4string="+proj=longlat +datum=WGS84 +no_defs")
areas_shifted <- sf::st_shift_longitude(area_2)
areas_cropped <- sf::st_crop(areas_shifted, xmin = 170, xmax = 230,
ymin = 50, ymax = 67)
areas_cropped <- cbind(areas_cropped, sf::st_coordinates(sf::st_centroid(areas_cropped)))
areas_cropped$nudge_y <- 0
areas_cropped$nudge_y[areas_cropped$REP_AREA == "543"] <- -0.5
areas_cropped$nudge_y[areas_cropped$REP_AREA == "519"] <- 0.1
areas_cropped$nudge_x <- 0
areas_cropped$nudge_x[areas_cropped$REP_AREA == "514"] <- -1
(ggAlaska <- ggplot2::ggplot() +
theme(legend.position = "none",
panel.grid.minor = element_line(colour = "grey50")
) +
geom_sf(data = AK_cropped, aes(fill = ID)) +
scale_fill_manual(values=c('grey20','grey40','grey80')) +
geom_sf(data = areas_cropped,
fill=NA, color='grey50') +
scale_x_continuous(minor_breaks = seq(170, 230, 1)) +
guides(fill = guide_legend(legend.position = "none")) +
xlab('') + ylab('')
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.