Skip to content

Commit

Permalink
close #141
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Aug 19, 2021
1 parent 3ae98f0 commit 7a23b4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 16 additions & 5 deletions R/visualisation_recipe.estimate_predicted.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
#' x <- estimate_relation(glm(vs ~ mpg, data = mtcars, family = "binomial"))
#' plot(visualisation_recipe(x))
#' plot(visualisation_recipe(x, show_data = "jitter", point = list(height = 0.03)))
#'
#' # Multiple CIs ---------------------
#' x <- estimate_relation(lm(mpg ~ disp, data = mtcars), ci = c(.50, .80, .95))
#' plot(x)
#' }
#' \donttest{
#' # Bayesian models ---------------------
Expand Down Expand Up @@ -191,10 +195,16 @@ visualisation_recipe.estimate_predicted <- function(x,
if (is.null(alpha) && is.null(linetype)) { # If interaction, omit uncertainty
if ("iter_1" %in% names(data)) {
layers[[paste0("l", l)]] <- .visualisation_predicted_iterations(data, x1, fill = color, ribbon = ribbon)
l <- l + 1
} else {
layers[[paste0("l", l)]] <- .visualisation_predicted_ribbon(data, x1, y = "Predicted", fill = color, ribbon = ribbon)

ci_lows <- names(data)[grepl("CI_low", names(data), fixed = TRUE)]
ci_highs <- names(data)[grepl("CI_high", names(data), fixed = TRUE)]
for(i in 1:length(ci_lows)) {
layers[[paste0("l", l)]] <- .visualisation_predicted_ribbon(data, x1, y = "Predicted", fill = color, ci_low = ci_lows[i], ci_high = ci_highs[i], ribbon = ribbon)
l <- l + 1
}
}
l <- l + 1
}

# Line
Expand Down Expand Up @@ -269,15 +279,16 @@ visualisation_recipe.estimate_predicted <- function(x,

# Layer - Ribbon -------------------------------------------------------------

.visualisation_predicted_ribbon <- function(data, x1, y, fill, group = NULL, ribbon = NULL) {
.visualisation_predicted_ribbon <- function(data, x1, y, fill, group = NULL, ci_low = "CI_low", ci_high = "CI_high", ribbon = NULL) {

out <- list(
geom = "ribbon",
data = data,
aes = list(
y = y,
x = x1,
ymin = "CI_low",
ymax = "CI_high",
ymin = ci_low,
ymax = ci_high,
fill = fill,
group = group
),
Expand Down
4 changes: 4 additions & 0 deletions man/visualisation_recipe.estimate_predicted.Rd

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

0 comments on commit 7a23b4c

Please sign in to comment.