Skip to content

Commit 0cfa9d8

Browse files
Merge pull request #70 from teunbrand/compat_ggplot2_400
Compatibility with ggplot2 4.0.0
2 parents 4bb2934 + 0fe94b1 commit 0cfa9d8

12 files changed

+22
-30
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Imports:
4747
officedown (>= 0.2.2),
4848
purrr (>= 0.3.4),
4949
rlang (>= 0.3.4),
50-
scales (>= 1.0.0),
50+
scales (>= 1.4.0),
5151
stringr (>= 1.4.0),
5252
tibble (>= 2.1.3),
5353
tidyr (>= 0.8.3),

R/atlas-color-scales.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ scale_atlas <- function(aesthetics, use_black = FALSE, order = 1:6, darken = 0,
6969
values[ai] <- scales::alpha(values[ai], alpha[ai])
7070
}
7171

72-
pal <- function(n) {
73-
if (n > length(values)) {
74-
warning("Insufficient values in manual scale. ", n, " needed but only ",
75-
length(values), " provided.", call. = FALSE)
76-
}
77-
values
78-
}
72+
pal <- scales::manual_pal(values, "colour")
7973
ggplot2::discrete_scale(aesthetics, palette = pal, ...)
8074
}

R/lcrost-color-scales.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ scale_lcrost <- function(aesthetics, use_black = FALSE, order = 1:8,
7070
values[ai] <- scales::alpha(values[ai], alpha[ai])
7171
}
7272

73-
pal <- function(n) {
74-
if (n > length(values)) {
75-
warning("Insufficient values in manual scale. ", n, " needed but only ",
76-
length(values), " provided.", call. = FALSE)
77-
}
78-
values
79-
}
73+
pal <- scales::manual_pal(values, "colour")
8074
ggplot2::discrete_scale(aesthetics, palette = pal, ...)
8175
}

R/okabeito-color-scales.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ scale_okabeito <- function(aesthetics, use_black = FALSE, order = 1:8,
6969
values[ai] <- scales::alpha(values[ai], alpha[ai])
7070
}
7171

72-
pal <- function(n) {
73-
if (n > length(values)) {
74-
warning("Insufficient values in manual scale. ", n, " needed but only ",
75-
length(values), " provided.", call. = FALSE)
76-
}
77-
values
78-
}
72+
pal <- scales::manual_pal(values, "colour")
7973
ggplot2::discrete_scale(aesthetics, palette = pal, ...)
8074
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# atlas colors work
2+
3+
This manual palette can handle a maximum of 6 values. You have supplied 10
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Lisa Charlotte Rost colors work
2+
3+
This manual palette can handle a maximum of 8 values. You have supplied 10
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Okabe Ito colors work
2+
3+
This manual palette can handle a maximum of 8 values. You have supplied 10
4+

tests/testthat/test-atlas-color-scales.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ test_that("atlas colors work", {
2323
scale_color_atlas() +
2424
theme_atlas()
2525

26-
expect_warning(ggplot2::ggplot_build(plot3), "Insufficient values")
27-
expect_warning(ggplot2::ggplot_build(plot3), "only 6 provided")
26+
expect_snapshot_warning(ggplot2::ggplot_build(plot3))
2827
vdiffr::expect_doppelganger("atlas_color", plot)
2928
vdiffr::expect_doppelganger("atlas_fill",
3029
plot2 + scale_fill_atlas(use_black = TRUE))

tests/testthat/test-lcrost-color-scales.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ test_that("Lisa Charlotte Rost colors work", {
2323
scale_color_lcrost() +
2424
theme_atlas()
2525

26-
expect_warning(ggplot2::ggplot_build(plot3), "Insufficient values")
27-
expect_warning(ggplot2::ggplot_build(plot3), "only 8 provided")
26+
expect_snapshot_warning(ggplot2::ggplot_build(plot3))
2827
vdiffr::expect_doppelganger("lcrost_color", plot)
2928
vdiffr::expect_doppelganger("lcrost_fill",
3029
plot2 + scale_fill_lcrost(use_black = TRUE))

tests/testthat/test-okabeito-color-scales.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ test_that("Okabe Ito colors work", {
2323
scale_color_okabeito() +
2424
theme_atlas()
2525

26-
expect_warning(ggplot2::ggplot_build(plot3), "Insufficient values")
27-
expect_warning(ggplot2::ggplot_build(plot3), "only 8 provided")
26+
expect_snapshot_warning(ggplot2::ggplot_build(plot3))
2827
vdiffr::expect_doppelganger("okabeito_color", plot)
2928
vdiffr::expect_doppelganger("okabeito_fill",
3029
plot2 + scale_fill_okabeito(use_black = TRUE))

0 commit comments

Comments
 (0)