diff --git a/NEWS.md b/NEWS.md index 6cf4cb55..9b43cc6d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,17 +1,27 @@ # tidyterra (development version) +**tidyterra** has been accepted on JOSS. Please use the result of +`citation("tidyterra")` or the following string: + +> Hernangómez, D. (2023). "Using the tidyverse with terra objects: the tidyterra +> package." *Journal of Open Source Software*, *8*(91), 5751. ISSN 2475-9066, +> + +Other changes on this version: + - Support for SpatRasters with a color table - `autoplot.SpatRaster()` can detect now SpatRasters with color tables. - `geom_spatraster()` can detect now SpatRasters with color tables. - New scales for plotting SpatRasters with color tables: `scale_fill_coltab()` and rest of family scales (`colour`). - tidyverse verbs keeps the associated `coltab` of a SpatRaster. -- By default all the discrete scales of tidyterra now have the following +- By default all the discrete scales of **tidyterra** now have the following setup: `na.translate = FALSE`. +- By default, all the non-discrete (e.g. continuous or breaks) scales of + **tidyterra** have now `na.value = "transparent"` (#120). - Enhanced `glimpse.Spat()` with meta-information on type of geometry, crs, etc. - New messaging interface thanks to [**cli**](https://cli.r-lib.org/) package. -- Update citation. # tidyterra 0.4.1 diff --git a/R/scales_coltab.R b/R/scales_coltab.R index f83a67d8..918b5c3e 100644 --- a/R/scales_coltab.R +++ b/R/scales_coltab.R @@ -61,7 +61,7 @@ #' } scale_fill_coltab <- function(data, ..., alpha = 1, na.translate = FALSE, - na.value = NA, + na.value = "transparent", drop = TRUE) { getcols <- get_coltab_pal(data) if (is.null(getcols)) { @@ -88,7 +88,7 @@ scale_fill_coltab <- function(data, ..., alpha = 1, #' @rdname scale_coltab #' @export scale_colour_coltab <- function(data, ..., alpha = 1, na.translate = FALSE, - na.value = NA, drop = TRUE) { + na.value = "transparent", drop = TRUE) { getcols <- get_coltab_pal(data) if (is.null(getcols)) { return(ggplot2::geom_blank()) diff --git a/R/scales_cross_blended.R b/R/scales_cross_blended.R index d46a12fe..642576ed 100644 --- a/R/scales_cross_blended.R +++ b/R/scales_cross_blended.R @@ -37,10 +37,14 @@ #' @name scale_cross_blended #' #' @inheritDotParams ggplot2::discrete_scale breaks:drop -#' @inheritDotParams ggplot2::continuous_scale breaks:labels na.value +#' @inheritDotParams ggplot2::continuous_scale breaks:labels #' @inheritDotParams ggplot2::binned_scale breaks:limits nice.breaks #' @param na.translate Should `NA` values be removed from the legend? Default #' is `TRUE`. +#' @param na.value Missing values will be replaced with this value. By default, +#' \CRANpkg{tidyterra} uses `na.value = "transparent"` so cells with `NA` are +#' not filled. See also +#' [#120](https://github.com/dieghernan/tidyterra/issues/120). #' @param drop Should unused factor levels be omitted from the scale? The #' default (`TRUE`) removes unused factors. #' @inheritParams ggplot2::scale_fill_viridis_b @@ -233,7 +237,7 @@ scale_colour_cross_blended_d <- function(palette = "cold_humid", ..., #' @rdname scale_cross_blended scale_fill_cross_blended_c <- function(palette = "cold_humid", ..., alpha = 1, direction = 1, - na.value = NA, guide = "colourbar") { + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -264,7 +268,7 @@ scale_fill_cross_blended_c <- function(palette = "cold_humid", ..., #' @rdname scale_cross_blended scale_colour_cross_blended_c <- function(palette = "cold_humid", ..., alpha = 1, direction = 1, - na.value = NA, guide = "colourbar") { + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -294,7 +298,7 @@ scale_colour_cross_blended_c <- function(palette = "cold_humid", ..., #' @rdname scale_cross_blended scale_fill_cross_blended_b <- function(palette = "cold_humid", ..., alpha = 1, direction = 1, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -323,7 +327,7 @@ scale_fill_cross_blended_b <- function(palette = "cold_humid", ..., #' @rdname scale_cross_blended scale_colour_cross_blended_b <- function(palette = "cold_humid", ..., alpha = 1, direction = 1, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -476,7 +480,7 @@ scale_fill_cross_blended_tint_c <- function(palette = "cold_humid", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") @@ -521,7 +525,7 @@ scale_colour_cross_blended_tint_c <- function(palette = "cold_humid", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") @@ -566,7 +570,7 @@ scale_fill_cross_blended_tint_b <- function(palette = "cold_humid", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") @@ -612,7 +616,7 @@ scale_colour_cross_blended_tint_b <- function(palette = "cold_humid", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") diff --git a/R/scales_hypso.R b/R/scales_hypso.R index 5b2a9f82..f67815cf 100644 --- a/R/scales_hypso.R +++ b/R/scales_hypso.R @@ -40,7 +40,7 @@ #' @name scale_hypso #' #' @inheritDotParams ggplot2::discrete_scale breaks:drop -#' @inheritDotParams ggplot2::continuous_scale breaks:labels na.value +#' @inheritDotParams ggplot2::continuous_scale breaks:labels #' @inheritDotParams ggplot2::binned_scale breaks:limits nice.breaks #' @inheritParams scale_cross_blended #' @param palette A valid palette name. The name is matched to the list of @@ -224,7 +224,7 @@ scale_colour_hypso_d <- function(palette = "etopo1_hypso", ..., #' @rdname scale_hypso scale_fill_hypso_c <- function(palette = "etopo1_hypso", ..., alpha = 1, direction = 1, - na.value = NA, guide = "colourbar") { + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -254,7 +254,7 @@ scale_fill_hypso_c <- function(palette = "etopo1_hypso", ..., #' @rdname scale_hypso scale_colour_hypso_c <- function(palette = "etopo1_hypso", ..., alpha = 1, direction = 1, - na.value = NA, guide = "colourbar") { + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -284,7 +284,7 @@ scale_colour_hypso_c <- function(palette = "etopo1_hypso", ..., #' @rdname scale_hypso scale_fill_hypso_b <- function(palette = "etopo1_hypso", ..., alpha = 1, direction = 1, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -313,7 +313,7 @@ scale_fill_hypso_b <- function(palette = "etopo1_hypso", ..., #' @rdname scale_hypso scale_colour_hypso_b <- function(palette = "etopo1_hypso", ..., alpha = 1, direction = 1, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -463,7 +463,7 @@ scale_fill_hypso_tint_c <- function(palette = "etopo1_hypso", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") @@ -507,7 +507,7 @@ scale_colour_hypso_tint_c <- function(palette = "etopo1_hypso", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") @@ -552,7 +552,7 @@ scale_fill_hypso_tint_b <- function(palette = "etopo1_hypso", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -596,7 +596,7 @@ scale_colour_hypso_tint_b <- function(palette = "etopo1_hypso", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } diff --git a/R/scales_terrain.R b/R/scales_terrain.R index 735b67ec..954c18a1 100644 --- a/R/scales_terrain.R +++ b/R/scales_terrain.R @@ -23,7 +23,7 @@ #' @name scale_terrain #' #' @inheritDotParams ggplot2::discrete_scale breaks:drop -#' @inheritDotParams ggplot2::continuous_scale breaks:labels na.value +#' @inheritDotParams ggplot2::continuous_scale breaks:labels #' @inheritDotParams ggplot2::binned_scale breaks:limits nice.breaks #' @inheritParams scale_cross_blended #' @@ -127,7 +127,7 @@ scale_colour_terrain_d <- function(..., alpha = 1, direction = 1, #' @export #' @rdname scale_terrain scale_fill_terrain_c <- function(..., alpha = 1, direction = 1, - na.value = NA, guide = "colourbar") { + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -152,7 +152,7 @@ scale_fill_terrain_c <- function(..., alpha = 1, direction = 1, #' @export #' @rdname scale_terrain scale_colour_terrain_c <- function(..., alpha = 1, direction = 1, - na.value = NA, guide = "colourbar") { + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -178,7 +178,7 @@ scale_colour_terrain_c <- function(..., alpha = 1, direction = 1, #' @export #' @rdname scale_terrain scale_fill_terrain_b <- function(..., alpha = 1, direction = 1, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -203,7 +203,7 @@ scale_fill_terrain_b <- function(..., alpha = 1, direction = 1, #' @export #' @rdname scale_terrain scale_colour_terrain_b <- function(..., alpha = 1, direction = 1, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } diff --git a/R/scales_whitebox.R b/R/scales_whitebox.R index 7ea16b81..725eb217 100644 --- a/R/scales_whitebox.R +++ b/R/scales_whitebox.R @@ -27,7 +27,7 @@ #' @name scale_whitebox #' #' @inheritDotParams ggplot2::discrete_scale breaks:drop -#' @inheritDotParams ggplot2::continuous_scale breaks:labels na.value +#' @inheritDotParams ggplot2::continuous_scale breaks:labels #' @inheritDotParams ggplot2::binned_scale breaks:limits nice.breaks #' @inheritParams scale_cross_blended #' @param palette A valid palette name. The name is matched to the list of @@ -153,7 +153,7 @@ scale_colour_whitebox_d <- function(palette = "high_relief", ..., #' @rdname scale_whitebox scale_fill_whitebox_c <- function(palette = "high_relief", ..., alpha = 1, direction = 1, - na.value = NA, guide = "colourbar") { + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -182,7 +182,7 @@ scale_fill_whitebox_c <- function(palette = "high_relief", ..., #' @rdname scale_whitebox scale_colour_whitebox_c <- function(palette = "high_relief", ..., alpha = 1, direction = 1, - na.value = NA, guide = "colourbar") { + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -212,7 +212,7 @@ scale_colour_whitebox_c <- function(palette = "high_relief", ..., #' @rdname scale_whitebox scale_fill_whitebox_b <- function(palette = "high_relief", ..., alpha = 1, direction = 1, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -242,7 +242,7 @@ scale_fill_whitebox_b <- function(palette = "high_relief", ..., #' @rdname scale_whitebox scale_colour_whitebox_b <- function(palette = "high_relief", ..., alpha = 1, direction = 1, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } diff --git a/R/scales_wiki.R b/R/scales_wiki.R index 346b0172..70303e6a 100644 --- a/R/scales_wiki.R +++ b/R/scales_wiki.R @@ -27,12 +27,12 @@ #' #' @name scale_wiki #' +#' @inheritParams scale_cross_blended #' @inheritDotParams ggplot2::discrete_scale breaks:drop -#' @inheritDotParams ggplot2::continuous_scale breaks:labels na.value +#' @inheritDotParams ggplot2::continuous_scale breaks:labels #' @inheritDotParams ggplot2::binned_scale breaks:limits nice.breaks #' @inheritParams ggplot2::scale_fill_viridis_b #' @inheritParams ggplot2::continuous_scale -#' @inheritParams scale_cross_blended #' @seealso [terra::plot()], [ggplot2::scale_fill_viridis_c()] #' #' See also \pkg{ggplot2} docs on additional `...` parameters: @@ -140,7 +140,7 @@ scale_color_wiki_d <- scale_colour_wiki_d #' @export #' @rdname scale_wiki scale_fill_wiki_c <- function(..., alpha = 1, direction = 1, - na.value = NA, guide = "colourbar") { + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -167,7 +167,7 @@ scale_fill_wiki_c <- function(..., alpha = 1, direction = 1, #' @export #' @rdname scale_wiki scale_colour_wiki_c <- function(..., alpha = 1, direction = 1, - na.value = NA, guide = "colourbar") { + na.value = "transparent", guide = "colourbar") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -199,7 +199,7 @@ scale_color_wiki_c <- scale_colour_wiki_c #' @export #' @rdname scale_wiki scale_fill_wiki_b <- function(..., alpha = 1, direction = 1, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } @@ -226,7 +226,7 @@ scale_fill_wiki_b <- function(..., alpha = 1, direction = 1, #' @export #' @rdname scale_wiki scale_colour_wiki_b <- function(..., alpha = 1, direction = 1, - na.value = NA, guide = "coloursteps") { + na.value = "transparent", guide = "coloursteps") { if (alpha < 0 || alpha > 1) { cli::cli_abort("{.arg alpha} {.field {alpha}} not in {.field [0,1]}") } diff --git a/R/stat_spatraster.R b/R/stat_spatraster.R index f93a83ac..a0b0db4d 100644 --- a/R/stat_spatraster.R +++ b/R/stat_spatraster.R @@ -47,7 +47,7 @@ #' aes(color = after_stat(value)), #' geom = "point", maxcell = 250 #' ) + -#' scale_colour_viridis_c(na.value = NA) + +#' scale_colour_viridis_c(na.value = "transparent") + #' facet_wrap(~lyr) #' #' # Using points and labels @@ -68,7 +68,7 @@ #' alpha = 0.85, #' maxcell = 20 #' ) + -#' scale_colour_viridis_c(na.value = NA) +#' scale_colour_viridis_c(na.value = "transparent") #' } stat_spatraster <- function(mapping = aes(), data, diff --git a/README.md b/README.md index c6678a60..bc80545b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ results](https://badges.cranchecks.info/worst/tidyterra.svg)](https://cran.r-pro [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) -[![Stack Exchange questions](https://img.shields.io/stackexchange/stackoverflow/t/tidyterra?logo=stackoverflow&label=stackoverflow%20q%26a)](https://stackoverflow.com/questions/tagged/tidyterra) +[![Stack Exchange +questions](https://img.shields.io/stackexchange/stackoverflow/t/tidyterra?logo=stackoverflow&label=stackoverflow%20q%26a)](https://stackoverflow.com/questions/tagged/tidyterra) @@ -311,7 +312,8 @@ Check our [FAQs](https://dieghernan.github.io/tidyterra/articles/faqs.html) or open a new [issue](https://github.com/dieghernan/tidyterra/issues)! -You can also ask in [Stack Overflow](https://stackoverflow.com/) using the tag +You can also ask in [Stack Overflow](https://stackoverflow.com/) using +the tag [`tidyterra`](https://stackoverflow.com/questions/tagged/tidyterra). ## Citation diff --git a/codemeta.json b/codemeta.json index d320ed3a..b2a1bafd 100644 --- a/codemeta.json +++ b/codemeta.json @@ -308,7 +308,7 @@ "SystemRequirements": null }, "keywords": ["r", "terra", "ggplot-extension", "r-spatial", "rspatial", "r-package", "rstats", "rstats-package", "cran", "cran-r"], - "fileSize": "3441.821KB", + "fileSize": "3441.735KB", "citation": [ { "@type": "ScholarlyArticle", diff --git a/img/README-example-temp-2.png b/img/README-example-temp-2.png index 7cbfaba3..ec4b4f1c 100644 Binary files a/img/README-example-temp-2.png and b/img/README-example-temp-2.png differ diff --git a/inst/WORDLIST b/inst/WORDLIST index 55377c9a..ff9be693 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -7,9 +7,9 @@ Colorimetric Coords DOI EPSG -Hernangomez Hijmans Hypsometric +ISSN JOSS LiDAR Maungawhau @@ -83,7 +83,6 @@ terra tibble tibbles tidyr -tidyterra’ tidyverse tif unevaluated diff --git a/man/geom_spatraster.Rd b/man/geom_spatraster.Rd index e661f79d..92623050 100644 --- a/man/geom_spatraster.Rd +++ b/man/geom_spatraster.Rd @@ -226,7 +226,7 @@ ggplot() + aes(color = after_stat(value)), geom = "point", maxcell = 250 ) + - scale_colour_viridis_c(na.value = NA) + + scale_colour_viridis_c(na.value = "transparent") + facet_wrap(~lyr) # Using points and labels @@ -247,7 +247,7 @@ ggplot() + alpha = 0.85, maxcell = 20 ) + - scale_colour_viridis_c(na.value = NA) + scale_colour_viridis_c(na.value = "transparent") } } \seealso{ diff --git a/man/scale_coltab.Rd b/man/scale_coltab.Rd index 3ce70052..17dd5888 100644 --- a/man/scale_coltab.Rd +++ b/man/scale_coltab.Rd @@ -12,7 +12,7 @@ scale_fill_coltab( ..., alpha = 1, na.translate = FALSE, - na.value = NA, + na.value = "transparent", drop = TRUE ) @@ -21,7 +21,7 @@ scale_colour_coltab( ..., alpha = 1, na.translate = FALSE, - na.value = NA, + na.value = "transparent", drop = TRUE ) @@ -77,7 +77,10 @@ expand the scale by 5\% on each side for continuous variables, and by \item{na.translate}{Should \code{NA} values be removed from the legend? Default is \code{TRUE}.} -\item{na.value}{Missing values will be replaced with this value.} +\item{na.value}{Missing values will be replaced with this value. By default, +\CRANpkg{tidyterra} uses \code{na.value = "transparent"} so cells with \code{NA} are +not filled. See also +\href{https://github.com/dieghernan/tidyterra/issues/120}{#120}.} \item{drop}{Should unused factor levels be omitted from the scale? The default (\code{TRUE}) removes unused factors.} diff --git a/man/scale_cross_blended.Rd b/man/scale_cross_blended.Rd index b38297cf..36122527 100644 --- a/man/scale_cross_blended.Rd +++ b/man/scale_cross_blended.Rd @@ -56,7 +56,7 @@ scale_fill_cross_blended_c( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -65,7 +65,7 @@ scale_colour_cross_blended_c( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -74,7 +74,7 @@ scale_fill_cross_blended_b( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -83,7 +83,7 @@ scale_colour_cross_blended_b( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -114,7 +114,7 @@ scale_fill_cross_blended_tint_c( direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -125,7 +125,7 @@ scale_colour_cross_blended_tint_c( direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -136,7 +136,7 @@ scale_fill_cross_blended_tint_b( direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -147,7 +147,7 @@ scale_colour_cross_blended_tint_b( direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -221,7 +221,10 @@ is \code{TRUE}.} \item{drop}{Should unused factor levels be omitted from the scale? The default (\code{TRUE}) removes unused factors.} -\item{na.value}{Missing values will be replaced with this value.} +\item{na.value}{Missing values will be replaced with this value. By default, +\CRANpkg{tidyterra} uses \code{na.value = "transparent"} so cells with \code{NA} are +not filled. See also +\href{https://github.com/dieghernan/tidyterra/issues/120}{#120}.} \item{guide}{A function used to create a guide or its name. See \code{\link[ggplot2:guides]{guides()}} for more information.} diff --git a/man/scale_hypso.Rd b/man/scale_hypso.Rd index 30effd43..60064733 100644 --- a/man/scale_hypso.Rd +++ b/man/scale_hypso.Rd @@ -50,7 +50,7 @@ scale_fill_hypso_c( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -59,7 +59,7 @@ scale_colour_hypso_c( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -68,7 +68,7 @@ scale_fill_hypso_b( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -77,7 +77,7 @@ scale_colour_hypso_b( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -108,7 +108,7 @@ scale_fill_hypso_tint_c( direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -119,7 +119,7 @@ scale_colour_hypso_tint_c( direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -130,7 +130,7 @@ scale_fill_hypso_tint_b( direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -141,7 +141,7 @@ scale_colour_hypso_tint_b( direction = 1, values = NULL, limits = NULL, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -215,7 +215,10 @@ is \code{TRUE}.} \item{drop}{Should unused factor levels be omitted from the scale? The default (\code{TRUE}) removes unused factors.} -\item{na.value}{Missing values will be replaced with this value.} +\item{na.value}{Missing values will be replaced with this value. By default, +\CRANpkg{tidyterra} uses \code{na.value = "transparent"} so cells with \code{NA} are +not filled. See also +\href{https://github.com/dieghernan/tidyterra/issues/120}{#120}.} \item{guide}{A function used to create a guide or its name. See \code{\link[ggplot2:guides]{guides()}} for more information.} diff --git a/man/scale_terrain.Rd b/man/scale_terrain.Rd index 28842c06..e0213301 100644 --- a/man/scale_terrain.Rd +++ b/man/scale_terrain.Rd @@ -33,7 +33,7 @@ scale_fill_terrain_c( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -41,7 +41,7 @@ scale_colour_terrain_c( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -49,7 +49,7 @@ scale_fill_terrain_b( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -57,7 +57,7 @@ scale_colour_terrain_b( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) } @@ -133,7 +133,10 @@ is \code{TRUE}.} \item{drop}{Should unused factor levels be omitted from the scale? The default (\code{TRUE}) removes unused factors.} -\item{na.value}{Missing values will be replaced with this value.} +\item{na.value}{Missing values will be replaced with this value. By default, +\CRANpkg{tidyterra} uses \code{na.value = "transparent"} so cells with \code{NA} are +not filled. See also +\href{https://github.com/dieghernan/tidyterra/issues/120}{#120}.} \item{guide}{A function used to create a guide or its name. See \code{\link[ggplot2:guides]{guides()}} for more information.} diff --git a/man/scale_whitebox.Rd b/man/scale_whitebox.Rd index dde30b1a..60dd4035 100644 --- a/man/scale_whitebox.Rd +++ b/man/scale_whitebox.Rd @@ -41,7 +41,7 @@ scale_fill_whitebox_c( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -50,7 +50,7 @@ scale_colour_whitebox_c( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -59,7 +59,7 @@ scale_fill_whitebox_b( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -68,7 +68,7 @@ scale_colour_whitebox_b( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -150,7 +150,10 @@ is \code{TRUE}.} \item{drop}{Should unused factor levels be omitted from the scale? The default (\code{TRUE}) removes unused factors.} -\item{na.value}{Missing values will be replaced with this value.} +\item{na.value}{Missing values will be replaced with this value. By default, +\CRANpkg{tidyterra} uses \code{na.value = "transparent"} so cells with \code{NA} are +not filled. See also +\href{https://github.com/dieghernan/tidyterra/issues/120}{#120}.} \item{guide}{A function used to create a guide or its name. See \code{\link[ggplot2:guides]{guides()}} for more information.} diff --git a/man/scale_wiki.Rd b/man/scale_wiki.Rd index eb50d81e..e6685247 100644 --- a/man/scale_wiki.Rd +++ b/man/scale_wiki.Rd @@ -35,7 +35,7 @@ scale_fill_wiki_c( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -43,7 +43,7 @@ scale_colour_wiki_c( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "colourbar" ) @@ -51,7 +51,7 @@ scale_fill_wiki_b( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -59,7 +59,7 @@ scale_colour_wiki_b( ..., alpha = 1, direction = 1, - na.value = NA, + na.value = "transparent", guide = "coloursteps" ) @@ -130,7 +130,10 @@ breaks are given explicitly.} \item{na.translate}{Should \code{NA} values be removed from the legend? Default is \code{TRUE}.} -\item{na.value}{Missing values will be replaced with this value.} +\item{na.value}{Missing values will be replaced with this value. By default, +\CRANpkg{tidyterra} uses \code{na.value = "transparent"} so cells with \code{NA} are +not filled. See also +\href{https://github.com/dieghernan/tidyterra/issues/120}{#120}.} \item{drop}{Should unused factor levels be omitted from the scale? The default (\code{TRUE}) removes unused factors.} diff --git a/vignettes/articles/faqs.Rmd b/vignettes/articles/faqs.Rmd index c6ed5ed6..2fd2b132 100644 --- a/vignettes/articles/faqs.Rmd +++ b/vignettes/articles/faqs.Rmd @@ -33,11 +33,17 @@ cat("\n- Discussions: ", dis) cat("\n") ``` -## NA values are shown in gray color {#nas-remove} +## `NA` values are shown in gray color {#nas-remove} This is the default behavior produced by the **ggplot2** package. **tidyterra** color scales (i.e., `scale_fill_whitebox_c()`, etc.), has by default the -parameter `na.value` set to `NA`, that prevents NA values to be plotted. +parameter `na.value` set to `"transparent"`, that prevents `NA` values to be +filled[^1]. + +[^1]: `na.value = NA` could be used as well for the same purpose in most of the + cases, however when the proportion of non-`NA`s is small it can produce + undesired results, see + [#120](https://github.com/dieghernan/tidyterra/issues/120). ```{r remove-nas} library(terra) @@ -72,7 +78,7 @@ def + # Modify with scales def + - scale_fill_continuous(na.value = NA) + + scale_fill_continuous(na.value = "transparent") + labs( title = "Default colors on ggplot2", subtitle = "But NAs are not plotted" @@ -182,7 +188,10 @@ hill <- shade(slope, aspect, 10, 340) ggplot() + geom_spatraster(data = hill, show.legend = FALSE) + # Note the scale, grey colours - scale_fill_gradientn(colours = grey(0:100 / 100), na.value = NA) + + scale_fill_gradientn( + colours = grey(0:100 / 100), + na.value = "transparent" + ) + labs(title = "A hillshade plot with grey colors") ```