Skip to content

Commit

Permalink
args
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 17, 2024
1 parent 4736d08 commit b4cce11
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
2 changes: 2 additions & 0 deletions R/plot.check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ plot.see_check_model <- function(x,
p$PP_CHECK <- plot.see_performance_pp_check(
x$PP_CHECK,
style = style,
size_line = size_line,
size_point = size_point,
type = type,
check_model = TRUE,
adjust_legend = TRUE,
Expand Down
39 changes: 29 additions & 10 deletions R/plot.check_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ data_plot.performance_pp_check <- function(x, type = "density", ...) {
#' @export
print.see_performance_pp_check <- function(x,
size_line = 0.5,
size_point = 2,
line_alpha = 0.15,
size_bar = 0.7,
style = theme_lucid,
Expand All @@ -96,6 +97,7 @@ print.see_performance_pp_check <- function(x,
p1 <- .plot_pp_check(
x,
size_line,
size_point,
line_alpha,
theme_style = style,
colors = colors,
Expand All @@ -119,6 +121,7 @@ print.see_performance_pp_check <- function(x,
#' @export
plot.see_performance_pp_check <- function(x,
size_line = 0.5,
size_point = 2,
line_alpha = 0.15,
size_bar = 0.7,
style = theme_lucid,
Expand All @@ -130,7 +133,7 @@ plot.see_performance_pp_check <- function(x,
check_range <- isTRUE(attributes(x)$check_range)
plot_type <- attributes(x)$type

if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) {
if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) { # nolint
type <- plot_type
} else {
type <- match.arg(type)
Expand All @@ -143,6 +146,7 @@ plot.see_performance_pp_check <- function(x,
p1 <- .plot_pp_check(
x,
size_line,
size_point,
line_alpha,
theme_style = style,
colors = colors,
Expand All @@ -161,7 +165,15 @@ plot.see_performance_pp_check <- function(x,



.plot_pp_check <- function(x, size_line, line_alpha, theme_style, colors, type = "density", x_limits = NULL, ...) {
.plot_pp_check <- function(x,
size_line,
size_point,
line_alpha,
theme_style,
colors,
type = "density",
x_limits = NULL,
...) {
info <- attr(x, "info")

# default bandwidth, for smooting
Expand All @@ -174,7 +186,7 @@ plot.see_performance_pp_check <- function(x,
suggest_dots <- (minfo$is_bernoulli || minfo$is_count || minfo$is_ordinal || minfo$is_categorical)

if (!is.null(type) && type %in% c("discrete_dots", "discrete_interval", "discrete_both") && suggest_dots) {
out <- .plot_check_predictions_dots(x, colors, info, size_line, line_alpha, type, ...)
out <- .plot_check_predictions_dots(x, colors, info, size_line, size_point, line_alpha, type, ...)
} else {
if (suggest_dots) {
insight::format_alert(
Expand Down Expand Up @@ -261,7 +273,14 @@ plot.see_performance_pp_check <- function(x,
}


.plot_check_predictions_dots <- function(x, colors, info, size_line, line_alpha, type = "discrete_dots", ...) {
.plot_check_predictions_dots <- function(x,
colors,
info,
size_line,
size_point,
line_alpha,
type = "discrete_dots",
...) {
# make sure we have a factor, so "table()" generates frequencies for all levels
# for each group - we need tables of same size to bind data frames
x$values <- as.factor(x$values)
Expand Down Expand Up @@ -308,8 +327,8 @@ plot.see_performance_pp_check <- function(x,
color = .data$key
),
position = ggplot2::position_nudge(x = 0.2),
size = 1.5 * size_line,
linewidth = 1.5 * size_line,
size = size_line,
linewidth = size_line,
stroke = 0,
shape = 16
) +
Expand All @@ -320,7 +339,7 @@ plot.see_performance_pp_check <- function(x,
y = .data$count,
color = .data$key
),
size = 6 * size_line,
size = size_point,
stroke = 0,
shape = 16
)
Expand All @@ -342,7 +361,7 @@ plot.see_performance_pp_check <- function(x,
),
alpha = line_alpha,
position = ggplot2::position_jitter(width = 0.1, height = 0.02),
size = 4 * size_line,
size = size_point * 0.8,
stroke = 0,
shape = 16
) +
Expand All @@ -355,15 +374,15 @@ plot.see_performance_pp_check <- function(x,
group = .data$grp,
color = .data$key
),
size = 4 * size_line
size = size_point * 0.8
) +
ggplot2::geom_point(
data = x[x$key == "Observed data", ],
mapping = ggplot2::aes(
x = .data$x,
y = .data$count
),
size = 6 * size_line,
size = size_point,
shape = 21,
colour = "white",
fill = colors[1]
Expand Down
4 changes: 4 additions & 0 deletions man/print.see_performance_pp_check.Rd

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

1 comment on commit b4cce11

@strengejacke
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, that was supposed to be pushed into a new PR, not into main :-/
Still struggling with stashing/migrating changes in git.

Please sign in to comment.