Skip to content

Commit

Permalink
Update guardian code
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhodge931 committed Nov 7, 2023
1 parent bc1dd21 commit ce01d40
Show file tree
Hide file tree
Showing 45 changed files with 161 additions and 157 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export(gg_step)
export(gg_text)
export(gg_tile)
export(gg_violin)
export(jumble)
export(guardian)
export(light_mode)
export(str_keep_seq)
importFrom(magrittr,"%>%")
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ggblanket 5.1.0900

* Updated colours: `"steelblue"` where no col aesthetic, `jumble` where discrete and less than 5 colours, scales:hue_pal otherwise, `viridis::mako` reversed for continuous, and `"grey"` for NA.
* Updated colours: `"steelblue"` where no col aesthetic, `guardian` where discrete and less than 5 colours, scales:hue_pal otherwise, `viridis::mako` reversed for continuous, and `"grey"` for NA.
* Breaking: removed all `pal_*` functions.
* Removed some unnecessary messages.
* Fixed bug where `col_breaks` was not working for a numeric `col`.
Expand Down
6 changes: 3 additions & 3 deletions R/gg_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -1222,16 +1222,16 @@ gg_area <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_bar.R
Original file line number Diff line number Diff line change
Expand Up @@ -1227,16 +1227,16 @@ gg_bar <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_bin_2d.R
Original file line number Diff line number Diff line change
Expand Up @@ -1248,16 +1248,16 @@ gg_bin_2d <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_blank.R
Original file line number Diff line number Diff line change
Expand Up @@ -1586,16 +1586,16 @@ gg_blank <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1227,16 +1227,16 @@ gg_boxplot <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_col.R
Original file line number Diff line number Diff line change
Expand Up @@ -1233,16 +1233,16 @@ gg_col <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_contour.R
Original file line number Diff line number Diff line change
Expand Up @@ -1295,16 +1295,16 @@ gg_contour <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_contour_filled.R
Original file line number Diff line number Diff line change
Expand Up @@ -1289,16 +1289,16 @@ gg_contour_filled <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_crossbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -1316,16 +1316,16 @@ gg_crossbar <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_density.R
Original file line number Diff line number Diff line change
Expand Up @@ -1228,16 +1228,16 @@ gg_density <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_density_2d.R
Original file line number Diff line number Diff line change
Expand Up @@ -1253,16 +1253,16 @@ gg_density_2d <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_density_2d_filled.R
Original file line number Diff line number Diff line change
Expand Up @@ -1243,16 +1243,16 @@ gg_density_2d_filled <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_errorbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -1313,16 +1313,16 @@ gg_errorbar <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_freqpoly.R
Original file line number Diff line number Diff line change
Expand Up @@ -1229,16 +1229,16 @@ gg_freqpoly <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_hex.R
Original file line number Diff line number Diff line change
Expand Up @@ -1253,16 +1253,16 @@ gg_hex <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_histogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -1228,16 +1228,16 @@ gg_histogram <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_jitter.R
Original file line number Diff line number Diff line change
Expand Up @@ -1227,16 +1227,16 @@ gg_jitter <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -1243,16 +1243,16 @@ gg_label <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
6 changes: 3 additions & 3 deletions R/gg_line.R
Original file line number Diff line number Diff line change
Expand Up @@ -1223,16 +1223,16 @@ gg_line <- function(
if (col_factor) col_n <- length(levels(col_vctr))
else if (col_character) {
col_unique <- unique(col_vctr)
col_n <- length(col_unique[!rlang::is_na(col_unique)])
col_n <- length(col_unique[!is.na(col_unique)])
}
else if (stat %in% c("contour_filled", "density_2d_filled")) {
col_n <- length(levels(dplyr::pull(plot_data, "level")))
}

if (rlang::is_null(pal)) {
if (stat %in% c("contour_filled", "density_2d_filled")) pal <- viridisLite::mako(n = col_n, direction = -1)
else if (col_n > 5) pal <- scales::hue_pal()(col_n)
else pal <- jumble(n = col_n)
else if (col_n > 4) pal <- scales::hue_pal()(col_n)
else pal <- guardian(n = col_n)
}
else if (rlang::is_null(names(pal))) pal <- pal[1:col_n]

Expand Down
Loading

0 comments on commit ce01d40

Please sign in to comment.