Skip to content

Commit 2deeca9

Browse files
committed
use x expression as axis label
1 parent 27c17d6 commit 2deeca9

10 files changed

+1235
-1215
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Add possibility for left-truncation to `ppc_km_overlay()` and `ppc_km_overlay_grouped()` by @Sakuski
44
* Added `ppc_loo_pit_ecdf()` by @TeemuSailynoja
55
* PPC "avg" functions (`ppc_scatter_avg()`, `ppc_error_scatter_avg()`, etc.) gain a `stat` argument to set the averaging function. (Suggestion of #348, @kruschke).
6+
* `ppc_error_scatter_avg_vs_x(x = some_expression)` labels the *x* axis with `some_expression`.
67

78
# bayesplot 1.12.0
89

R/ppc-errors.R

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -273,32 +273,37 @@ ppc_error_scatter_avg_grouped <-
273273
#' @param x A numeric vector the same length as `y` to use as the x-axis
274274
#' variable.
275275
#'
276-
ppc_error_scatter_avg_vs_x <-
277-
function(y,
278-
yrep,
279-
x,
280-
...,
281-
stat = "mean",
282-
size = 2.5,
283-
alpha = 0.8) {
284-
check_ignored_arguments(...)
276+
ppc_error_scatter_avg_vs_x <- function(
277+
y,
278+
yrep,
279+
x,
280+
...,
281+
stat = "mean",
282+
size = 2.5,
283+
alpha = 0.8
284+
) {
285+
check_ignored_arguments(...)
285286

286-
y <- validate_y(y)
287-
yrep <- validate_predictions(yrep, length(y))
288-
x <- validate_x(x, y)
289-
stat <- as_tagged_function({{ stat }})
290-
errors <- compute_errors(y, yrep)
291-
ppc_scatter_avg(
292-
y = x,
293-
yrep = errors,
294-
size = size,
295-
alpha = alpha,
296-
ref_line = FALSE,
297-
stat = stat
287+
y <- validate_y(y)
288+
yrep <- validate_predictions(yrep, length(y))
289+
qx <- enquo(x)
290+
x <- validate_x(x, y)
291+
stat <- as_tagged_function({{ stat }})
292+
errors <- compute_errors(y, yrep)
293+
ppc_scatter_avg(
294+
y = x,
295+
yrep = errors,
296+
size = size,
297+
alpha = alpha,
298+
ref_line = FALSE,
299+
stat = stat
300+
) +
301+
labs(
302+
x = error_avg_label(stat),
303+
y = as_label((qx))
298304
) +
299-
labs(x = error_avg_label(stat), y = expression(italic(x))) +
300-
coord_flip()
301-
}
305+
coord_flip()
306+
}
302307

303308

304309
#' @rdname PPC-errors
@@ -438,7 +443,7 @@ error_avg_label <- function(stat = NULL) {
438443
e <- sym("stat")
439444
}
440445
de <- deparse1(e)
441-
expr(paste((!!de))(italic(y) - italic(y)[rep]))
446+
expr(paste((!!de))*(italic(y) - italic(y)[rep]))
442447
}
443448

444449

R/ppc-scatterplots.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ yrep_avg_label <- function(stat = NULL) {
229229
e <- sym("stat")
230230
}
231231
de <- deparse1(e)
232-
expr(paste((!!de))(italic(y)[rep]))
232+
expr(paste((!!de))*(italic(y)[rep]))
233233
}
234234

235235
scatter_aes <- function(...) {

tests/testthat/_snaps/ppc-errors/ppc-error-scatter-avg-default.svg

Lines changed: 139 additions & 137 deletions
Loading

tests/testthat/_snaps/ppc-errors/ppc-error-scatter-avg-grouped-default.svg

Lines changed: 226 additions & 224 deletions
Loading

tests/testthat/_snaps/ppc-errors/ppc-error-scatter-avg-vs-x-default.svg

Lines changed: 138 additions & 136 deletions
Loading

tests/testthat/_snaps/ppc-scatterplots/ppc-scatter-avg-default.svg

Lines changed: 132 additions & 130 deletions
Loading

tests/testthat/_snaps/ppc-scatterplots/ppc-scatter-avg-grouped-default.svg

Lines changed: 220 additions & 218 deletions
Loading

tests/testthat/_snaps/ppc-scatterplots/ppc-scatter-avg-grouped-size-alpha-ref-line.svg

Lines changed: 216 additions & 214 deletions
Loading

tests/testthat/_snaps/ppc-scatterplots/ppc-scatter-avg-size-alpha.svg

Lines changed: 132 additions & 130 deletions
Loading

0 commit comments

Comments
 (0)