Skip to content

Commit

Permalink
Merge pull request #257 from stan-dev/feature-ppc_ribbon_obspoints
Browse files Browse the repository at this point in the history
Feature ppc ribbon obspoints
  • Loading branch information
jgabry committed Feb 22, 2021
2 parents 665c687 + 3169902 commit ecb1676
Show file tree
Hide file tree
Showing 12 changed files with 1,897 additions and 10 deletions.
33 changes: 26 additions & 7 deletions R/ppc-intervals.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,17 @@ ppc_intervals_grouped <- function(y,

#' @rdname PPC-intervals
#' @export
#' @param y_draw For ribbon plots only, a string specifying how to draw `y`. Can
#' be `"line"` (the default), `"points"`, or `"both"`.
ppc_ribbon <- function(y,
yrep,
x = NULL,
...,
prob = 0.5,
prob_outer = 0.9,
alpha = 0.33,
size = 0.25) {
size = 0.25,
y_draw = c("line", "points", "both")) {
check_ignored_arguments(...)

data <- ppc_intervals_data(
Expand All @@ -197,7 +200,8 @@ ppc_ribbon <- function(y,
size = size,
grouped = FALSE,
style = "ribbon",
x_lab = label_x(x)
x_lab = label_x(x),
y_draw = y_draw
)
}

Expand All @@ -213,7 +217,8 @@ ppc_ribbon_grouped <- function(y,
prob = 0.5,
prob_outer = 0.9,
alpha = 0.33,
size = 0.25) {
size = 0.25,
y_draw = c("line", "points", "both")) {
check_ignored_arguments(...)

data <- ppc_intervals_data(
Expand All @@ -234,7 +239,8 @@ ppc_ribbon_grouped <- function(y,
size = size,
grouped = TRUE,
style = "ribbon",
x_lab = label_x(x)
x_lab = label_x(x),
y_draw = y_draw
)
}

Expand Down Expand Up @@ -319,9 +325,11 @@ label_x <- function(x) {
size = 1,
grouped = FALSE,
style = c("intervals", "ribbon"),
x_lab = NULL) {
x_lab = NULL,
y_draw = c("line", "points", "both")) {

style <- match.arg(style)
y_draw <- match.arg(y_draw)

graph <- ggplot(
data = data,
Expand Down Expand Up @@ -349,11 +357,22 @@ label_x <- function(x) {
aes_(color = "yrep"),
size = size/2
) +
geom_blank(aes_(fill = "y")) +
geom_line(
geom_blank(aes_(fill = "y"))

if (y_draw == "line" || y_draw == "both") {
graph <- graph + geom_line(
aes_(y = ~ y_obs, color = "y"),
size = 0.5
)
}

if (y_draw == "points" || y_draw == "both") {
graph <- graph + geom_point(
mapping = aes_(y = ~ y_obs, color = "y", fill = "y"),
shape = 21,
size = 1.5
)
}
} else {
graph <- graph +
geom_pointrange(
Expand Down
9 changes: 7 additions & 2 deletions man/PPC-intervals.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/figs/deps.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- vdiffr-svg-engine: 1.0
- vdiffr: 0.3.2.2
- vdiffr: 0.3.3
- freetypeharfbuzz: 0.2.5
174 changes: 174 additions & 0 deletions tests/figs/ppc-intervals-ribbon/ppc-intervals-y-draw-both.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions tests/figs/ppc-intervals-ribbon/ppc-intervals-y-draw-line.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
171 changes: 171 additions & 0 deletions tests/figs/ppc-intervals-ribbon/ppc-intervals-y-draw-point.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
244 changes: 244 additions & 0 deletions tests/figs/ppc-intervals-ribbon/ppc-ribbon-grouped-default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
236 changes: 236 additions & 0 deletions tests/figs/ppc-intervals-ribbon/ppc-ribbon-grouped-x-values.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
346 changes: 346 additions & 0 deletions tests/figs/ppc-intervals-ribbon/ppc-ribbon-grouped-y-draw-both.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
244 changes: 244 additions & 0 deletions tests/figs/ppc-intervals-ribbon/ppc-ribbon-grouped-y-draw-line.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
340 changes: 340 additions & 0 deletions tests/figs/ppc-intervals-ribbon/ppc-ribbon-grouped-y-draw-point.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions tests/testthat/test-ppc-intervals.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,40 @@ test_that("ppc_ribbon renders correctly", {

p_50 <- ppc_ribbon(vdiff_y, vdiff_yrep, prob = 0.5)
vdiffr::expect_doppelganger("ppc_ribbon (interval width)", p_50)

p_line <- ppc_ribbon(vdiff_y, vdiff_yrep, y_draw = "line")
vdiffr::expect_doppelganger("ppc_intervals (y_draw = line)", p_line)

p_point <- ppc_ribbon(vdiff_y, vdiff_yrep, y_draw = "point")
vdiffr::expect_doppelganger("ppc_intervals (y_draw = point)", p_point)

p_both <- ppc_ribbon(vdiff_y, vdiff_yrep, y_draw = "both")
vdiffr::expect_doppelganger("ppc_intervals (y_draw = both)", p_both)
})

test_that("ppc_ribbon_grouped renders correctly", {
testthat::skip_on_cran()
testthat::skip_if_not_installed("vdiffr")

p_base <- ppc_ribbon_grouped(vdiff_y, vdiff_yrep, group = vdiff_group)
vdiffr::expect_doppelganger("ppc_ribbon_grouped (default)", p_base)

p_line <- ppc_ribbon_grouped(vdiff_y, vdiff_yrep, group = vdiff_group,
y_draw = "line")
vdiffr::expect_doppelganger("ppc_ribbon_grouped (y_draw = line)", p_line)

p_point <- ppc_ribbon_grouped(vdiff_y, vdiff_yrep, group = vdiff_group,
y_draw = "point")
vdiffr::expect_doppelganger("ppc_ribbon_grouped (y_draw = point)", p_point)

p_both <- ppc_ribbon_grouped(vdiff_y, vdiff_yrep, group = vdiff_group,
y_draw = "both")
vdiffr::expect_doppelganger("ppc_ribbon_grouped (y_draw = both)", p_both)

p_x <- ppc_ribbon_grouped(
y = vdiff_y,
yrep = vdiff_yrep,
x = vdiff_y,
group = vdiff_group)
vdiffr::expect_doppelganger("ppc_ribbon_grouped (x values)", p_x)
})

0 comments on commit ecb1676

Please sign in to comment.