Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 27, 2024
1 parent 9c255ea commit 1b73ae7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
12 changes: 11 additions & 1 deletion R/plot.parameters_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,16 @@ plot.see_parameters_model <- function(x,
min_ci <- min(x$CI_low, na.rm = TRUE)
max_ci <- max(x$CI_high, na.rm = TRUE)

# here we check if all facets have the same scale. If so, we set the scales
# to fixed, otherwise we set them to free_y (in facet_wrap). This removes
# a redundant scale for plots with identical scales.
check_scales <- split(x$Level, x$Group)
if (isTRUE(identical(unname(check_scales[-length(check_scales)]), unname(check_scales[-1])))) {
facet_scales <- "fixed"
} else {
facet_scales <- "free_y"
}

p <- ggplot2::ggplot(
x,
ggplot2::aes(
Expand Down Expand Up @@ -641,7 +651,7 @@ plot.see_parameters_model <- function(x,
colour = "white",
shape = 21
) +
ggplot2::facet_wrap(~Group, ncol = n_columns)
ggplot2::facet_wrap(~Group, ncol = n_columns, scales = facet_scales)

# add coefficients and CIs?
if (isTRUE(show_labels)) {
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-plot.parameters_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,23 @@ test_that("`plot.see_parameters_model()` random parameters works", {
fig = plot(out, sort = "ascending", show_labels = TRUE, show_intercept = FALSE)
)
})


test_that("`plot.see_parameters_model()` random parameters works", {
skip_if_not_installed("vdiffr")
skip_if_not_installed("lme4")
skip_if_not_installed("parameters")
data(sleepstudy, package = "lme4")

set.seed(12345)
sleepstudy$grp <- sample(1:5, size = 180, replace = TRUE)
model <- lmer(
Reaction ~ Days + (1 | grp) + (1 | Subject),
data = sleepstudy
)
out <- parameters::model_parameters(model, group_level = TRUE)
vdiffr::expect_doppelganger(
title = "plot.model_parameters_doublerandom",
fig = plot(out)
)
})
7 changes: 7 additions & 0 deletions vignettes/parameters.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ result <- model_parameters(model2)
plot(result)
```

### Including group levels of random effects

```{r}
result <- model_parameters(model3, group_level = TRUE)
plot(result)
```

### Changing parameter names in the plot

By default, `model_parameters()` returns a data frame, where the parameter names are found in the column `Parameter`. These names are used by default in the generated plot:
Expand Down

0 comments on commit 1b73ae7

Please sign in to comment.