Skip to content

Commit 7684000

Browse files
style and docs: run devtools::document() and styler::style_pkg() (#65)
Co-authored-by: sbreitbart-NOAA <[email protected]>
1 parent 98a774f commit 7684000

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

R/ggplot2-scales.R

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#' ggplot(mtcars, aes(mpg, disp, color = as.factor(gear))) +
2323
#' geom_point(size = 4) +
2424
#' scale_color_nmfs("regional",
25-
#' interpolate = FALSE,
26-
#' discrete = TRUE)
25+
#' interpolate = FALSE,
26+
#' discrete = TRUE
27+
#' )
2728
#' @export
2829
scale_color_nmfs <- function(
2930
palette = "oceans",
@@ -36,21 +37,24 @@ scale_color_nmfs <- function(
3637
pal_length <- length(nmfs_palettes[[palette]])
3738

3839
if (discrete) {
39-
if (interpolate){
40+
if (interpolate) {
4041
ggplot2::discrete_scale(
4142
aesthetics = "colour",
4243
palette = pal,
4344
...
4445
)
4546
} else {
4647
cli::cli_alert_info("The {palette} palette has {pal_length} colors.")
47-
rlang::warn(message = "An error will occur if there are too few palette colors for your plot.
48+
rlang::warn(
49+
message = "An error will occur if there are too few palette colors for your plot.
4850
To avoid this error, use a larger palette or `interpolate = TRUE`.",
49-
.frequency = "once",
50-
.frequency_id = "too_few_colors_warning_color")
51+
.frequency = "once",
52+
.frequency_id = "too_few_colors_warning_color"
53+
)
5154
ggplot2::scale_color_manual(
5255
values = nmfs_palette(palette)(pal_length),
53-
...)
56+
...
57+
)
5458
}
5559
} else {
5660
ggplot2::scale_color_gradientn(colours = pal(256), ...)
@@ -73,8 +77,9 @@ To avoid this error, use a larger palette or `interpolate = TRUE`.",
7377
#' ggplot(mtcars, aes(mpg, disp, color = as.factor(gear))) +
7478
#' geom_point(size = 4) +
7579
#' scale_fill_nmfs("regional",
76-
#' interpolate = FALSE,
77-
#' discrete = TRUE)
80+
#' interpolate = FALSE,
81+
#' discrete = TRUE
82+
#' )
7883
#' @export
7984
scale_fill_nmfs <- function(
8085
palette = "oceans",
@@ -87,21 +92,24 @@ scale_fill_nmfs <- function(
8792
pal_length <- length(nmfs_palettes[[palette]])
8893

8994
if (discrete) {
90-
if (interpolate){
95+
if (interpolate) {
9196
ggplot2::discrete_scale(
9297
aesthetics = "fill",
9398
palette = pal,
9499
...
95100
)
96101
} else {
97102
cli::cli_alert_info("The {palette} palette has {pal_length} colors.")
98-
rlang::warn(message = "An error will occur if there are too few palette colors for your plot.
103+
rlang::warn(
104+
message = "An error will occur if there are too few palette colors for your plot.
99105
To avoid this error, use a larger palette or `interpolate = TRUE`.",
100-
.frequency = "once",
101-
.frequency_id = "too_few_colors_warning_fill")
106+
.frequency = "once",
107+
.frequency_id = "too_few_colors_warning_fill"
108+
)
102109
ggplot2::scale_fill_manual(
103110
values = nmfs_palette(palette)(pal_length),
104-
...)
111+
...
112+
)
105113
}
106114
} else {
107115
ggplot2::scale_fill_gradientn(colours = pal(256), ...)

man/scale_color_nmfs.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scale_fill_nmfs.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-scale-fill.R

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ test_that("nmfs_cols creates a valid plot", {
1010
p_discrete_interp <- ggplot(mpg, aes(manufacturer, fill = manufacturer)) +
1111
geom_bar() +
1212
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
13-
scale_fill_nmfs(palette = "oceans",
14-
discrete = TRUE,
15-
interpolate = TRUE)
13+
scale_fill_nmfs(
14+
palette = "oceans",
15+
discrete = TRUE,
16+
interpolate = TRUE
17+
)
1618

1719
test_that("scale_fill works with discrete = TRUE", {
1820
skip_on_cran()
@@ -28,14 +30,20 @@ test_that("scale_fill works with discrete = TRUE", {
2830
)
2931
})
3032

31-
p_discrete <- ggplot(mpg, aes(x = cyl,
32-
y = cty,
33-
fill = as.factor(cyl))) +
34-
geom_point(shape = 22,
35-
size = 3) +
36-
scale_fill_nmfs(palette = "oceans",
37-
discrete = TRUE,
38-
interpolate = FALSE)
33+
p_discrete <- ggplot(mpg, aes(
34+
x = cyl,
35+
y = cty,
36+
fill = as.factor(cyl)
37+
)) +
38+
geom_point(
39+
shape = 22,
40+
size = 3
41+
) +
42+
scale_fill_nmfs(
43+
palette = "oceans",
44+
discrete = TRUE,
45+
interpolate = FALSE
46+
)
3947

4048
test_that("scale_fill works with discrete = TRUE and interpolate = FALSE", {
4149
skip_on_cran()

0 commit comments

Comments
 (0)