Skip to content

Commit

Permalink
add weight to default aes in slabinterval
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Feb 27, 2024
1 parent 5fecac3 commit 2db2aef
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 4 deletions.
5 changes: 4 additions & 1 deletion R/stat_slabinterval.R
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ StatSlabinterval = ggproto("StatSlabinterval", AbstractStatSlabinterval,
(when `orientation = "horizontal"` with sample data).',
y = 'y position of the geometry (when orientation = `"horizontal"`); or sample data to be summarized
(when `orientation = "vertical"` with sample data).',
weight = 'When using samples (i.e. the `x` and `y` aesthetics, not `xdist` or `ydist`), optional
weights to be applied to each draw.',
xdist = 'When using analytical distributions, distribution to map on the x axis: a \\pkg{distributional}
object (e.g. [dist_normal()]) or a [posterior::rvar()] object.',
ydist = 'When using analytical distributions, distribution to map on the y axis: a \\pkg{distributional}
Expand All @@ -476,7 +478,8 @@ StatSlabinterval = ggproto("StatSlabinterval", AbstractStatSlabinterval,
arg6 = NULL,
arg7 = NULL,
arg8 = NULL,
arg9 = NULL
arg9 = NULL,
weight = NULL
), AbstractStatSlabinterval$default_aes),

# interval parameter used to determine if the stat re-groups
Expand Down
2 changes: 2 additions & 0 deletions man/stat_ccdfinterval.Rd

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

2 changes: 2 additions & 0 deletions man/stat_cdfinterval.Rd

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

2 changes: 2 additions & 0 deletions man/stat_dots.Rd

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

2 changes: 2 additions & 0 deletions man/stat_dotsinterval.Rd

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

2 changes: 2 additions & 0 deletions man/stat_eye.Rd

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

2 changes: 2 additions & 0 deletions man/stat_gradientinterval.Rd

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

2 changes: 2 additions & 0 deletions man/stat_halfeye.Rd

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

2 changes: 2 additions & 0 deletions man/stat_histinterval.Rd

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

2 changes: 2 additions & 0 deletions man/stat_interval.Rd

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

2 changes: 2 additions & 0 deletions man/stat_lineribbon.Rd

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

2 changes: 2 additions & 0 deletions man/stat_mcse_dots.Rd

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

2 changes: 2 additions & 0 deletions man/stat_pointinterval.Rd

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

2 changes: 2 additions & 0 deletions man/stat_ribbon.Rd

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

2 changes: 2 additions & 0 deletions man/stat_slab.Rd

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

2 changes: 2 additions & 0 deletions man/stat_slabinterval.Rd

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

2 changes: 2 additions & 0 deletions man/stat_spike.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test.geom_slabinterval.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Author: mjskay
###############################################################################

library(dplyr)


suppressPackageStartupMessages(suppressWarnings({
library(dplyr)
}))


# group_slab_data_by -------------------------------------------------
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test.stat_sample_slabinterval.R
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,33 @@ test_that("logical conditions at bin edges on histograms work", {
})


# weights -----------------------------------------------------------------

test_that("sample weights work", {
df = data.frame(
x = 1:9/10,
w = 0:8
)

p = ggplot(df, aes(x, weight = w))

ld_slab = layer_data(p + stat_slab(n = 9, density = "unbounded", .width = .5))
expect_equal(
ld_slab$pdf,
density(df$x, weights = df$w/36, bw = bandwidth_dpi(df$x), n = 9, cut = 0)$y
)
expect_equal(ld_slab$cdf, cumsum(df$w/36))
expect_equal(ld_slab$.width, c(rep(NA, 5), rep(0.5, 3), NA))

ld_interval = layer_data(p + stat_pointinterval(.width = .5))
expect_equal(ld_interval$x, 0.7)
expect_equal(ld_interval$xmin, weighted_quantile(df$x, 0.25, weights = df$w, names = FALSE))
expect_equal(ld_interval$xmax, weighted_quantile(df$x, 0.75, weights = df$w, names = FALSE))
ld_interval_mean = layer_data(p + stat_pointinterval(.width = .5, point_interval = mean_qi))
expect_equal(ld_interval_mean$x, 2/3)
})


# deprecated params -------------------------------------------------------

test_that("slab_type throws appropriate warnings and errors", {
Expand Down

0 comments on commit 2db2aef

Please sign in to comment.