Skip to content
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
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
linters: linters_with_defaults(
pipe_consistency_linter(pipe = "auto")
pipe_consistency_linter(pipe = "auto"),
object_name_linter(styles = "snake_case", regexes = c("na\\.value"))
)
exclude: "^#| fig.alt = "
encoding: "UTF-8"
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# sgplot (development version)

* Deprecate `na_colour` arguments in `scale_fill_continuous_sg()`/
`scale_colour_continuous_sg()` functions in favour of new argument, `na.value`
(#73).

* Vignettes are converted to articles. Vignettes are now not available to view
locally and only via the
[pkgdown site](https://scotgovanalysis.github.io/sgplot/) (#66).
Expand Down
35 changes: 28 additions & 7 deletions R/scale_continuous_sg.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#'
#' @param palette Name of palette to use; e.g. "main", "sequential", "focus".
#' Default value is "sequential".
#' @param na_colour Colour to set for missing values.
#' @param na.value Colour to set for missing values.
#' @param guide A name or function used to create guide. Default is "colourbar".
#' @inheritParams scale_colour_discrete_sg
#' @param na_colour `r lifecycle::badge('deprecated')` Use `na.value` instead.
#'
#' @returns ggplot2 continuous colour/fill scale
#'
Expand All @@ -24,9 +25,19 @@
scale_colour_continuous_sg <- function(palette = "sequential",
palette_type = "sg",
reverse = FALSE,
na_colour = "grey50",
na.value = "grey50",
guide = "colourbar",
...) {
...,
na_colour = deprecated()) {

if (lifecycle::is_present(na_colour)) {
lifecycle::deprecate_warn(
when = "0.4.0",
what = "scale_colour_continuous_sg(na_colour)",
with = "scale_colour_continuous_sg(na.value)"
)
na.value <- na_colour
}

colours <-
sg_palette(palette = palette,
Expand All @@ -36,7 +47,7 @@ scale_colour_continuous_sg <- function(palette = "sequential",
ggplot2::continuous_scale(
aesthetics = "colour",
palette = scales::gradient_n_pal(colours, values = NULL, "Lab"),
na.value = na_colour,
na.value = na.value,
guide = guide,
...
)
Expand All @@ -49,9 +60,19 @@ scale_colour_continuous_sg <- function(palette = "sequential",
scale_fill_continuous_sg <- function(palette = "sequential",
palette_type = "sg",
reverse = FALSE,
na_colour = "grey50",
na.value = "grey50",
guide = "colourbar",
...) {
...,
na_colour = deprecated()) {

if (lifecycle::is_present(na_colour)) {
lifecycle::deprecate_warn(
when = "0.4.0",
what = "scale_fill_continuous_sg(na_colour)",
with = "scale_fill_continuous_sg(na.value)"
)
na.value <- na_colour
}

colours <-
sg_palette(palette = palette,
Expand All @@ -61,7 +82,7 @@ scale_fill_continuous_sg <- function(palette = "sequential",
ggplot2::continuous_scale(
aesthetics = "fill",
palette = scales::gradient_n_pal(colours, values = NULL, "Lab"),
na.value = na_colour,
na.value = na.value,
guide = guide,
...
)
Expand Down
16 changes: 8 additions & 8 deletions R/use_sgplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ use_sgplot <- function(palette_type = "sg",
# Use sgplot colour palette ----

options(
ggplot2.continuous.fill = function() {
scale_fill_continuous_sg(palette_type = palette_type)
ggplot2.continuous.fill = function(...) {
scale_fill_continuous_sg(palette_type = palette_type, ...)
},
ggplot2.continuous.colour = function() {
scale_colour_continuous_sg(palette_type = palette_type)
ggplot2.continuous.colour = function(...) {
scale_colour_continuous_sg(palette_type = palette_type, ...)
},
ggplot2.discrete.fill = function() {
scale_fill_discrete_sg(palette_type = palette_type)
ggplot2.discrete.fill = function(...) {
scale_fill_discrete_sg(palette_type = palette_type, ...)
},
ggplot2.discrete.colour = function() {
scale_colour_discrete_sg(palette_type = palette_type)
ggplot2.discrete.colour = function(...) {
scale_colour_discrete_sg(palette_type = palette_type, ...)
}
)

Expand Down
14 changes: 9 additions & 5 deletions man/scale_colour_continuous_sg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading