Skip to content

Commit

Permalink
add two tests, one verifying the unweighted density and one verifying…
Browse files Browse the repository at this point in the history
… the weighted density
  • Loading branch information
Joran Elias committed Feb 6, 2024
1 parent a57c86a commit 6e08e8e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/testthat/test_stat_density_ridges.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,23 @@ test_that("alternative quantile function can be provided", {
expect_setequal(out$datatype, c("ridgeline", "vline"))
expect_equal(out$x[out$datatype=="vline"], mean(df$x))
})

test_that("unweighted densities are calculated correctly", {
df <- data.frame(x = rnorm(100),wts = runif(100))
df$wts <- df$wts / sum(df$wts)

gg_no_wts <- layer_data(ggplot(df, aes(x = x, y = 0)) + stat_density_ridges())
d_no_wts <- stats::density(df$x)

expect_equal(gg_no_wts$density,d_no_wts$y)
})

test_that("weighted densities are calculated correctly", {
df <- data.frame(x = rnorm(100),wts = runif(100))
df$wts <- df$wts / sum(df$wts)

gg_wts <- layer_data(ggplot(df, aes(x = x, y = 0, weight = wts)) + stat_density_ridges())
d_wts <- stats::density(df$x,weights = df$wts)

expect_equal(gg_wts$density,d_wts$y)
})

0 comments on commit 6e08e8e

Please sign in to comment.