Skip to content

Commit 0b43dfd

Browse files
authored
Merge pull request #31 from KopfLab/sk-dev
prep for version 0.4 & cran release
2 parents 1d1c798 + 7345ed3 commit 0b43dfd

46 files changed

Lines changed: 3336 additions & 486 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.Rbuildignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@
2323
^codecov.yml$
2424
^doc$
2525
^Meta$
26-
^ggstackplot\.Rproj$
2726
^codecov\.yml$
2827
^\.covrignore$

DESCRIPTION

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ggstackplot
22
Title: Create Overlapping Stacked Plots
3-
Version: 0.3.0
3+
Version: 0.3.9999
44
Authors@R:
55
c(person(
66
given = "Sebastian", family = "Kopf",
@@ -29,22 +29,26 @@ Description:
2929
License: MIT + file LICENSE
3030
Encoding: UTF-8
3131
Roxygen: list(markdown = TRUE)
32-
RoxygenNote: 7.2.3
32+
RoxygenNote: 7.3.2
33+
Depends:
34+
R (>= 4.1.0)
3335
Imports:
36+
rlang,
37+
cli,
3438
methods,
35-
rlang (>= 0.4.11),
39+
lifecycle,
3640
tidyselect,
3741
dplyr,
3842
tidyr,
3943
ggplot2,
4044
cowplot,
4145
RColorBrewer
4246
Suggests:
43-
covr,
4447
knitr,
4548
rmarkdown,
46-
roxygen2,
47-
testthat,
48-
lifecycle,
49-
scales
49+
testthat (>= 3.0.0),
50+
vdiffr,
51+
scales,
52+
pangaear
53+
Config/testthat/edition: 3
5054
VignetteBuilder: knitr

NAMESPACE

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
export(":=")
4-
export(.data)
5-
export(as_label)
6-
export(as_name)
73
export(assemble_stackplot)
8-
export(enquo)
9-
export(enquos)
104
export(ggstackplot)
115
export(prepare_stackplot)
126
export(theme_stackplot)
7+
import(cli)
138
import(ggplot2)
149
import(rlang)
15-
importFrom(rlang,":=")
16-
importFrom(rlang,.data)
17-
importFrom(rlang,as_label)
18-
importFrom(rlang,as_name)
19-
importFrom(rlang,enquo)
20-
importFrom(rlang,enquos)
10+
importFrom(lifecycle,deprecated)

NEWS.md

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
1-
# isoorbi 1.1.0
1+
# ggstackplot 0.4.0
22

3-
This is a major release adding substantial new features and fixing a few bugs.
3+
This is the first public release adding all core ggstackplot functionality.
44

5-
## Breaking changes
5+
## Features
66

7-
There are no breaking changes in this release (all changes and new features are backwards compatible).
8-
9-
## New features
10-
11-
* implemented block annotation functionality (FIXME: explain more)
12-
* implemented package settings (FIXME: explain more)
13-
14-
## Enhancements
15-
16-
* removed dependency on `stringr`
17-
* implemented native pipe `|>` (R version requirement increased to 4.1.0) and removed dependency on `magrittr`
18-
* added `.by` parameter for `orbi_summarize_results()` for option to manually adjust grouping
19-
20-
## Bug fixes
21-
22-
* `dplyr` changes to joins with explicit `multiple` argument are now implemented (#10)
23-
24-
# isorbi 1.0.0
25-
26-
First public release.
7+
* generate horizontally and vertically stacked plots
8+
* modify color, plot templates, and individual plot elements

R/ggstackplot-package.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## usethis namespace: start
2+
#' @import rlang
3+
#' @import cli
4+
#' @import ggplot2
5+
#' @importFrom lifecycle deprecated
6+
## usethis namespace: end
7+
NULL
8+
9+
#' @aliases NULL ggstackplot-package
10+
#' @details
11+
#' `r lifecycle::badge("stable")`
12+
#'
13+
#' Have you ever wanted to create (partly) overlapping line plots with matched color-coding of the data and axes? These kinds of plots are common in climatology and oceanography research but there is not an easy way to create them with ggplot facets. The ggstackplot package builds on [ggplot2](https://ggplot2.tidyverse.org/) to provide a straightforward approach to building these kinds of plots while retaining the powerful grammar of graphics approach of ggplots. Check out the functionality provided by ggstackplots at <https://ggstackplot.kopflab.org>
14+
#'
15+
"_PACKAGE"

R/ggstackplot.R

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#' @param shared_axis_size if simplify_shared_axes is true, this determines the size of the shared axis relative to the size of a single plot
2222
#' @param template a template plot (ggplot object) to use for the stacked plots
2323
#' @param add a list of ggplot component calls to add to specific panel plots, either by panel variable name (named list) or index (unnamed list)
24-
#' @param debug debug flag to print the stackplot tibble and gtable intermediates
24+
#' @param debug `r lifecycle::badge("experimental")` debug flag to print the stackplot tibble and gtable intermediates
2525
#' @examples
2626
#'
2727
#' # 1 step stackplot (most common use)
@@ -122,48 +122,48 @@ prepare_stackplot <- function(
122122

123123
# internal function to prepare the data for a ggstackplot
124124
create_stackplot_tibble <- function(
125-
data, x, y, remove_na = TRUE, color = NA, palette = NA, both_axes = FALSE, alternate_axes = FALSE, switch_axes = FALSE) {
125+
data, x, y, remove_na = TRUE, color = NA, palette = NA, both_axes = FALSE, alternate_axes = FALSE, switch_axes = FALSE, call = caller_env()) {
126126

127127
# do we have a data frame?
128128
if (missing(data) || !is.data.frame(data)) {
129-
abort("`data` must be a data frame or tibble.")
129+
cli_abort("`data` must be a data frame or tibble.", call = call)
130130
}
131131

132132
# do x and y evaluate correctly?
133133
x <- try_fetch(
134134
tidyselect::eval_select(rlang::enexpr(x), data),
135135
error = function(cnd) {
136-
abort(
136+
cli_abort(
137137
"`x` must be a valid tidyselect expression.",
138-
parent = cnd
138+
parent = cnd, call = call
139139
)
140140
}
141141
)
142142
y <- try_fetch(
143143
tidyselect::eval_select(rlang::enexpr(y), data),
144144
error = function(cnd) {
145-
abort(
145+
cli_abort(
146146
"`y` must be a valid tidyselect expression.",
147-
parent = cnd
147+
parent = cnd, call = call
148148
)
149149
}
150150
)
151151

152152
# do we have at least 1 x and 1 y?
153153
if (length(x) < 1 || length(y) < 1) {
154-
abort(c(
154+
cli_abort(c(
155155
"insufficient number of columns",
156156
"x" = if (length(x) < 1) "no `x` column selected",
157157
"x" = if (length(y) < 1) "no `y` column selected"
158-
))
158+
), call = call)
159159
}
160160
# do we have both multiple x AND y?
161161
if (length(x) > 1 && length(y) > 1) {
162-
abort(c(
162+
cli_abort(c(
163163
"too many columns, only x OR y can select multiple columns",
164164
"x" = if (length(x) < 1) "no `x` column selected",
165165
"x" = if (length(y) < 1) "no `y` column selected"
166-
))
166+
), call = call)
167167
}
168168

169169
# do we have valid remove_na, both_axes, alternate_axes, and switch_axes (the booleans)
@@ -204,15 +204,15 @@ create_stackplot_tibble <- function(
204204
# do we have a valid length for color or palette?
205205
stopifnot("can only set either `color` or `palette`, not both" = is.na(color) | is.na(palette))
206206
if (!(is.character(color) || all(is.na(color))) || !length(color) %in% c(1L, nrow(config))) {
207-
abort(sprintf("`color` must be either a single color or one for each variable (%d)", nrow(config)))
207+
cli_abort(sprintf("`color` must be either a single color or one for each variable (%d)", nrow(config)), call = call)
208208
}
209209
if (!all(is.na(palette))) {
210210
# palette argument provided
211211
if (is_scalar_character(palette) && palette %in% rownames(RColorBrewer::brewer.pal.info) && RColorBrewer::brewer.pal.info[palette, 1] >= nrow(config)) {
212212
color = RColorBrewer::brewer.pal(RColorBrewer::brewer.pal.info[palette, 1], palette)[1:nrow(config)]
213213
} else
214214
sprintf("`palette` must be a string identifying a valid RColorBrewer palette with at least %d colors. Use `RColorBrewer::display.brewer.all()` to see all available palettes.", nrow(config)) |>
215-
abort()
215+
cli_abort(call = call)
216216
}
217217

218218

@@ -290,28 +290,33 @@ assemble_stackplot <- function(prepared_stackplot, overlap = 0, simplify_shared_
290290
}
291291

292292
# internal function to great a list of gtables for the combined plot
293-
create_stackplot_gtables <- function(prepared_stackplot, overlap, simplify_shared_axis, shared_axis_size) {
293+
create_stackplot_gtables <- function(prepared_stackplot, overlap, simplify_shared_axis, shared_axis_size, call = caller_env()) {
294294

295295
# do we have a data frame?
296296
req_cols <- c(".var", "config", "data", "plot", "theme")
297297
if (missing(prepared_stackplot) || !is.data.frame(prepared_stackplot) ||
298298
!all(req_cols %in% names(prepared_stackplot))) {
299-
abort(
300-
sprintf("`prepared_stackplot` must be a data frame or tibble with columns '%s'", paste(req_cols, collapse = "', '"))
299+
cli_abort(
300+
"{.var prepared_stackplot} must be a data frame or tibble with columns
301+
{.emph {req_cols}}", call = call
301302
)
302303
}
303304

304305
# do we have a valid overlap value?
305306
if (missing(overlap) || !is.numeric(overlap) || !all(overlap >= 0) || !all(overlap <= 1) ||
306307
!length(overlap) %in% c(1L, nrow(prepared_stackplot) - 1L)) {
307-
abort(sprintf("`overlap` must be either a single numeric value (between 0 and 1) or one for each sequential plot overlap (%d)",
308-
nrow(prepared_stackplot) - 1L))
308+
cli_abort(
309+
c("{.var overlap} must be either a single numeric value (between 0 and 1)
310+
or a vector with {nrow(prepared_stackplot) - 1L} numbers, one for the
311+
overlap of each sequential plot",
312+
"x" = "{.var overlap} is a {.obj_type_friendly {overlap}}"),
313+
call = call)
309314
}
310315

311316
# combine plots and themes and assembel the gtables
312317
gtables <- prepared_stackplot |>
313318
combine_plot_theme_add(simplify_shared_axis = simplify_shared_axis, include_adds = TRUE) |>
314-
tidyr::unnest(.data$config) |>
319+
tidyr::unnest("config") |>
315320
dplyr::select(".var", ".direction", "plot_w_theme") |>
316321
# could think about relative sizing here with size_adjust but that doesn't seem like a feature we need
317322
dplyr::mutate(

R/helpers.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#' Recommended base theme for stacked gg plots
44
#'
5+
#' Returns a basic ggplot2 theme that extends [ggplot2::theme_bw()] with a transparent plot background to make sure overlapping plots do not cover each other up.
56
#'
6-
#'
7-
#' @return `ggplot2::theme()` object
7+
#' @return [ggplot2::theme()] object
88
#' @examples
99
#' library(ggplot2)
1010
#' template <- ggplot() + geom_line() + theme_stackplot()
@@ -208,21 +208,21 @@ process_add_ons <- function(prepared_stackplot, add) {
208208
sprintf("no match for `add` component(s) '%s' in variables ('%s')",
209209
paste(add_names[is.na(add_indices)], collapse = "', '"),
210210
paste(prepared_stackplot$.var, collapse = "', '")) |>
211-
abort()
211+
cli_abort()
212212
}
213213

214214
# check for indices outside what's possible
215215
if (any(out_of_range <- !add_indices %in% seq_along(prepared_stackplot$.var))) {
216216
sprintf("`add` component(s) index out of range: %s",
217217
paste(add_indices[out_of_range], collapse = ", ")) |>
218-
abort()
218+
cli_abort()
219219
}
220220

221221
# check for duplicates
222222
if (any(dups <- duplicated(add_indices))) {
223223
sprintf("multiple `add` component definitions for variable(s) '%s'",
224224
paste(prepared_stackplot$.var[unique(add_indices[dups])], collapse = "', '" )) |>
225-
abort()
225+
cli_abort()
226226
}
227227

228228
# store adds
@@ -295,7 +295,7 @@ combine_plot_theme_add <- function(prepared_stackplot, simplify_shared_axis, inc
295295
if(!is.null(simplify_axis)) {
296296
if (any(grepl(sprintf("scale_%s_", simplify_axis), as.character(add)))) {
297297
sprintf("invalid add-on for '%s' plot: `%s`. Modifications of the shared %s-axis are not allowed because it can lead to deceptive visualizations. You can modify the shared axis in the template or switch to `simplify_shared_axis = FALSE`.", var, as_label(add), simplify_axis) |>
298-
abort()
298+
cli_abort()
299299
}
300300
}
301301

R/import-standalone-purrr.R

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Standalone file: do not edit by hand
2-
# Source: <https://github.com/r-lib/rlang/blob/main/R/standalone-purrr.R>
2+
# Source: https://github.com/r-lib/rlang/blob/HEAD/R/standalone-purrr.R
3+
# Generated by: usethis::use_standalone("r-lib/rlang", "purrr")
34
# ----------------------------------------------------------------------
45
#
56
# ---
@@ -169,19 +170,15 @@ every <- function(.x, .p, ...) {
169170
.p <- as_function(.p, env = global_env())
170171

171172
for (i in seq_along(.x)) {
172-
if (!rlang::is_true(.p(.x[[i]], ...))) {
173-
return(FALSE)
174-
}
173+
if (!rlang::is_true(.p(.x[[i]], ...))) return(FALSE)
175174
}
176175
TRUE
177176
}
178177
some <- function(.x, .p, ...) {
179178
.p <- as_function(.p, env = global_env())
180179

181180
for (i in seq_along(.x)) {
182-
if (rlang::is_true(.p(.x[[i]], ...))) {
183-
return(TRUE)
184-
}
181+
if (rlang::is_true(.p(.x[[i]], ...))) return(TRUE)
185182
}
186183
FALSE
187184
}

R/package.R

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)