diff --git a/DESCRIPTION b/DESCRIPTION index aa9f0ba9..c38cf456 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,12 +33,12 @@ Imports: curl, dplyr, flextable, - ggmap, ggplot2, ggrepel, ggspatial, httr, - lubridate, + lubridate, + prettymapr, RColorBrewer, rmarkdown, readxl, diff --git a/R/anlzMWRmap.R b/R/anlzMWRmap.R index af989eba..f432f1c2 100644 --- a/R/anlzMWRmap.R +++ b/R/anlzMWRmap.R @@ -17,9 +17,9 @@ #' @param sumfun character indicating one of \code{"auto"} (default), \code{"mean"}, \code{"geomean"}, \code{"median"}, \code{"min"}, or \code{"max"}, see details #' @param crs numeric as a four-digit EPSG number for the coordinate reference system, see details #' @param zoom numeric indicating resolution of the base map, see details -#' @param addwater character string as \code{"low"}, \code{"medium"} (default), \code{"high"}, or \code{NULL} (to supress) to include water features with varying detail from the National Hydrography dataset, see details -#' @param watercol character string of color for water objects if \code{addwater = "nhd"} or \code{addwater = "osm"} -#' @param maptype character string for the base map type, see details +#' @param addwater character string as \code{"low"}, \code{"medium"} (default), \code{"high"}, or \code{NULL} (to suppress) to include water features with varying detail from the National Hydrography dataset, see details +#' @param watercol character string of color for water objects if \code{addwater} is not \code{NULL} +#' @param maptype character string as \code{"cartolight"}, \code{"cartodark"}, \code{"osm"}, \code{"hotstyle"}, or \code{NULL} (to suppress, default) indicating the basemap type, see details #' @param buffdist numeric for buffer around the bounding box for the selected sites in kilometers, see details #' @param scaledist character string indicating distance unit for the scale bar, \code{"km"} or \code{"mi"} #' @param northloc character string indicating location of the north arrow, see details @@ -43,7 +43,7 @@ #' #' Using \code{addwater = "medium"} (default) will include lines and polygons of natural water bodies defined using the National Hydrography Dataset (NHD). The level of detail can be changed to low or high using \code{addwater = "low"} or \code{addwater = "high"}, respectively. Use \code{addwater = NULL} to not show any water features. #' -#' A base map can be plotted using the \code{maptype} argument and is obtained from the \code{\link[ggmap]{get_stamenmap}} function of ggmap. The \code{zoom} value specifies the resolution of the map. Use higher values to download map tiles with greater resolution, although this increases the download time. The \code{maptype} argument describes the type of base map to download. Acceptable options include \code{"terrain"}, \code{"terrain-background"}, \code{"terrain-labels"}, \code{"terrain-lines"}, \code{"toner"}, \code{"toner-2010"}, \code{"toner-2011"}, \code{"toner-background"}, \code{"toner-hybrid"}, \code{"toner-labels"}, \code{"toner-lines"}, \code{"toner-lite"}, or \code{"watercolor"}. Use \code{maptype = NULL} to suppress the base map. +#' A base map can be plotted using the \code{maptype} argument and is obtained from the \code{\link[ggspatial]{annotation_map_tile}} function of ggspatial. The \code{zoom} value specifies the resolution of the map. Use higher values to download map tiles with greater resolution, although this increases the download time. The \code{maptype} argument describes the type of base map to download. Acceptable options include \code{"cartolight"}, \code{"cartodark"}, \code{"osm"}, or \code{"hotstyle"}. Use \code{maptype = NULL} to suppress the base map. #' #' The area around the summarized points can be increased or decreased using the \code{buffdist} argument. This creates a buffered area around the bounding box for the points, where the units are kilometers. #' @@ -154,9 +154,11 @@ anlzMWRmap<- function(res = NULL, param, acc = NULL, sit = NULL, fset = NULL, si if(!is.null(maptype)){ - bsmap <- suppressMessages(ggmap::get_stamenmap(bbox = dat_ext, maptype = maptype, zoom = zoom)) - m <- ggmap::ggmap(bsmap) + maptype <- match.arg(maptype, c( 'cartolight', 'cartodark', 'osm', 'hotstyle')) + m <- m + + ggspatial::annotation_map_tile(zoom = zoom, quiet = TRUE, progress = "none", type = maptype, cachedir = system.file("rosm.cache", package = "ggspatial")) + } if(!is.null(addwater)){ @@ -247,11 +249,13 @@ anlzMWRmap<- function(res = NULL, param, acc = NULL, sit = NULL, fset = NULL, si if(repel & !is.null(labsize)) m <- m + - ggrepel::geom_text_repel(data = tolab, ggplot2::aes(label = `Monitoring Location ID`, x = x, y = y), size = labsize) + ggspatial::geom_spatial_text_repel(data = tolab, ggplot2::aes(label = `Monitoring Location ID`, x = x, y = y), size = labsize, + inherit.aes = F, crs = 4326) if(!repel & !is.null(labsize)) - m <- m + - ggplot2::geom_text(data = tolab, ggplot2::aes(label = `Monitoring Location ID`, x = x, y = y), size = labsize) + m <- m + + ggspatial::geom_spatial_text_repel(data = tolab, ggplot2::aes(label = `Monitoring Location ID`, x = x, y = y), size = labsize, + inherit.aes = F, crs = 4326) if(!latlon) m <- m + @@ -265,10 +269,10 @@ anlzMWRmap<- function(res = NULL, param, acc = NULL, sit = NULL, fset = NULL, si sf::st_as_sfc(dat_ext) %>% sf::st_transform(crs = 4326) %>% sf::st_bbox() - + # set coordinates because vector not clipped m <- m + - ggplot2::coord_sf(xlim = dat_ext[c(1, 3)], ylim = dat_ext[c(2, 4)], expand = FALSE) + ggplot2::coord_sf(xlim = dat_ext[c(1, 3)], ylim = dat_ext[c(2, 4)], expand = FALSE, crs = 4326) return(m) diff --git a/man/anlzMWRmap.Rd b/man/anlzMWRmap.Rd index c6dd27bd..20039970 100644 --- a/man/anlzMWRmap.Rd +++ b/man/anlzMWRmap.Rd @@ -70,11 +70,11 @@ anlzMWRmap( \item{zoom}{numeric indicating resolution of the base map, see details} -\item{addwater}{character string as \code{"low"}, \code{"medium"} (default), \code{"high"}, or \code{NULL} (to supress) to include water features with varying detail from the National Hydrography dataset, see details} +\item{addwater}{character string as \code{"low"}, \code{"medium"} (default), \code{"high"}, or \code{NULL} (to suppress) to include water features with varying detail from the National Hydrography dataset, see details} -\item{watercol}{character string of color for water objects if \code{addwater = "nhd"} or \code{addwater = "osm"}} +\item{watercol}{character string of color for water objects if \code{addwater} is not \code{NULL}} -\item{maptype}{character string for the base map type, see details} +\item{maptype}{character string as \code{"cartolight"}, \code{"cartodark"}, \code{"osm"}, \code{"hotstyle"}, or \code{NULL} (to suppress, default) indicating the basemap type, see details} \item{buffdist}{numeric for buffer around the bounding box for the selected sites in kilometers, see details} @@ -109,7 +109,7 @@ The results shown on the map represent the parameter summary for each site withi Using \code{addwater = "medium"} (default) will include lines and polygons of natural water bodies defined using the National Hydrography Dataset (NHD). The level of detail can be changed to low or high using \code{addwater = "low"} or \code{addwater = "high"}, respectively. Use \code{addwater = NULL} to not show any water features. -A base map can be plotted using the \code{maptype} argument and is obtained from the \code{\link[ggmap]{get_stamenmap}} function of ggmap. The \code{zoom} value specifies the resolution of the map. Use higher values to download map tiles with greater resolution, although this increases the download time. The \code{maptype} argument describes the type of base map to download. Acceptable options include \code{"terrain"}, \code{"terrain-background"}, \code{"terrain-labels"}, \code{"terrain-lines"}, \code{"toner"}, \code{"toner-2010"}, \code{"toner-2011"}, \code{"toner-background"}, \code{"toner-hybrid"}, \code{"toner-labels"}, \code{"toner-lines"}, \code{"toner-lite"}, or \code{"watercolor"}. Use \code{maptype = NULL} to suppress the base map. +A base map can be plotted using the \code{maptype} argument and is obtained from the \code{\link[ggspatial]{annotation_map_tile}} function of ggspatial. The \code{zoom} value specifies the resolution of the map. Use higher values to download map tiles with greater resolution, although this increases the download time. The \code{maptype} argument describes the type of base map to download. Acceptable options include \code{"cartolight"}, \code{"cartodark"}, \code{"osm"}, or \code{"hotstyle"}. Use \code{maptype = NULL} to suppress the base map. The area around the summarized points can be increased or decreased using the \code{buffdist} argument. This creates a buffered area around the bounding box for the points, where the units are kilometers. diff --git a/tests/testthat/test-anlzMWRmap.R b/tests/testthat/test-anlzMWRmap.R index 3389e9ed..222de90a 100644 --- a/tests/testthat/test-anlzMWRmap.R +++ b/tests/testthat/test-anlzMWRmap.R @@ -6,7 +6,7 @@ test_that("Checking output format", { test_that("Checking output format, one site", { skip_on_cran() - result <- anlzMWRmap(res = resdat, param = 'DO', acc = accdat, sit = sitdat, warn = FALSE, site = 'ABT-026', addwater = NULL, maptype = 'terrain') + result <- anlzMWRmap(res = resdat, param = 'DO', acc = accdat, sit = sitdat, warn = FALSE, site = 'ABT-026', addwater = NULL, maptype = 'osm', zoom = 5) expect_s3_class(result, 'ggplot') }) diff --git a/vignettes/analysis.Rmd b/vignettes/analysis.Rmd index bd293af5..7d6ded4e 100644 --- a/vignettes/analysis.Rmd +++ b/vignettes/analysis.Rmd @@ -301,4 +301,22 @@ The buffered distance around the points can be increased using the `buffdist` ar anlzMWRmap(res = resdat, param = "DO", acc = accdat, sit = sitdat, buffdist = 20, warn = F) ``` -A base map can be included as well using the `maptype` argument. Options include any stamen map as `"terrain"`, `"terrain-background"` (default), `"terrain-labels"`, `"terrain-lines"`, `"toner"`, `"toner-2010"`, `"toner-2011"`, `"toner-background"`, `"toner-hybrid"`, `"toner-labels"`, `"toner-lines"`, `"toner-lite"`, or `"watercolor"`. The `zoom` argument can be helpful when using a basemap. The default `zoom` argument is set to 11 and decreasing the number will download a base map with lower resolution. This can decrease map processing times for large areas. +A base map can be included as well using the `maptype` argument. Options include `"cartolight"`, `"cartodark"`, `"osm"`, or `"hotstyle"`. The `zoom` argument can be helpful when using a basemap. The default `zoom` argument is set to 11 and decreasing the number will download a base map with lower resolution. This can decrease map processing times for large areas. + +A `"cartolight"` base map: + +```{r, fig.height = 6, fig.width = 6} +anlzMWRmap(res = resdat, param = "DO", acc = accdat, sit = sitdat, maptype = "cartolight", warn = F, addwater = NULL) +``` + +A `"osm"` base map: + +```{r, fig.height = 6, fig.width = 6} +anlzMWRmap(res = resdat, param = "DO", acc = accdat, sit = sitdat, maptype = "osm", warn = F, addwater = NULL) +``` + +A map with no base map or water bodies: + +```{r, fig.height = 6, fig.width = 6} +anlzMWRmap(res = resdat, param = "DO", acc = accdat, sit = sitdat, maptype = NULL, warn = F, addwater = NULL) +``` \ No newline at end of file