Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make na.value = "transparent" the default #122

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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,
> <https://doi.org/10.21105/joss.05751>

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

Expand Down
4 changes: 2 additions & 2 deletions R/scales_coltab.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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())
Expand Down
22 changes: 13 additions & 9 deletions R/scales_cross_blended.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
Expand Down Expand Up @@ -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]}")
Expand Down Expand Up @@ -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]}")
Expand Down Expand Up @@ -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]}")
Expand Down
18 changes: 9 additions & 9 deletions R/scales_hypso.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
Expand Down Expand Up @@ -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]}")
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand Down
10 changes: 5 additions & 5 deletions R/scales_terrain.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand Down Expand Up @@ -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]}")
}
Expand All @@ -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]}")
}
Expand All @@ -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]}")
}
Expand All @@ -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]}")
}
Expand Down
10 changes: 5 additions & 5 deletions R/scales_whitebox.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand Down
12 changes: 6 additions & 6 deletions R/scales_wiki.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]}")
}
Expand All @@ -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]}")
}
Expand Down Expand Up @@ -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]}")
}
Expand All @@ -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]}")
}
Expand Down
4 changes: 2 additions & 2 deletions R/stat_spatraster.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Loading