diff --git a/DESCRIPTION b/DESCRIPTION index 6a227617b..5e2fb3e49 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: see Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2' -Version: 0.8.3.1 +Version: 0.8.3.2 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index f8ac223fc..7a00b2417 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,10 @@ * Small adjustment to size of point geoms for `check_model()` plots. +* More arguments to change base font sizes and geom sizes are now passed to + downstream plot-functions (i.e., `plot()` for `check_model()` passes arguments + to change geom sizes to the underlying plot-functions). + # see 0.8.3 ## Major changes diff --git a/R/plot.binned_residuals.R b/R/plot.binned_residuals.R index 2c6aef930..5a098a534 100644 --- a/R/plot.binned_residuals.R +++ b/R/plot.binned_residuals.R @@ -1,4 +1,3 @@ -#' #' @export plot.see_binned_residuals <- function(x, size_line = 0.7, @@ -6,6 +5,7 @@ plot.see_binned_residuals <- function(x, colors = social_colors(c("blue", "red", "green")), show_smooth = FALSE, style = theme_lucid, + base_size = 10, ...) { x$se.lo <- -x$se if (length(unique(x$group)) > 1L) { @@ -106,7 +106,7 @@ plot.see_binned_residuals <- function(x, if (isTRUE(dots[["check_model"]])) { p <- p + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) diff --git a/R/plot.check_collinearity.R b/R/plot.check_collinearity.R index 331a28d45..06be132c0 100644 --- a/R/plot.check_collinearity.R +++ b/R/plot.check_collinearity.R @@ -20,6 +20,7 @@ plot.see_check_collinearity <- function(x, colors = c("#3aaf85", "#1b6ca8", "#cd201f"), size_point = 3.5, size_line = 0.8, + base_size = 10, ...) { if (is.null(data)) { dat <- insight::compact_list(.retrieve_data(x)) @@ -51,6 +52,7 @@ plot.see_check_collinearity <- function(x, dat, size_point = size_point, size_line = size_line, + base_size = base_size, colors = colors, ci_data = attributes(x)$CI, is_check_model = FALSE @@ -62,6 +64,7 @@ plot.see_check_collinearity <- function(x, size_point, size_line, theme_style = theme_lucid, + base_size = 10, colors = unname(social_colors(c("green", "blue", "red"))), ci_data = NULL, is_check_model = FALSE) { @@ -161,7 +164,7 @@ plot.see_check_collinearity <- function(x, guide = ggplot2::guide_legend(title = NULL) ) + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) + diff --git a/R/plot.check_heteroscedasticity.R b/R/plot.check_heteroscedasticity.R index 3a28fa9bf..9d6642dcd 100644 --- a/R/plot.check_heteroscedasticity.R +++ b/R/plot.check_heteroscedasticity.R @@ -4,6 +4,7 @@ #' `performance::check_heteroscedasticity()` function. #' #' @inheritParams data_plot +#' @inheritParams plot.see_check_normality #' #' @return A ggplot2-object. #' @@ -15,7 +16,7 @@ #' result #' plot(result, data = m) # data required for pkgdown #' @export -plot.see_check_heteroscedasticity <- function(x, data = NULL, ...) { +plot.see_check_heteroscedasticity <- function(x, data = NULL, size_point = 2, size_line = 0.8, base_size = 10, ...) { if (is.null(data)) { model <- .retrieve_data(x) } else { @@ -68,7 +69,7 @@ plot.see_check_heteroscedasticity <- function(x, data = NULL, ...) { x = stats::fitted(model), y = sqrt(abs(r)) ) - .plot_diag_homogeneity(dat, size_point = 2, size_line = 0.8, ...) + .plot_diag_homogeneity(dat, size_point = size_point, size_line = size_line, base_size = base_size, ...) } diff --git a/R/plot.check_homogeneity.R b/R/plot.check_homogeneity.R index ad3a9b313..ef9bb5e87 100644 --- a/R/plot.check_homogeneity.R +++ b/R/plot.check_homogeneity.R @@ -134,6 +134,7 @@ plot.see_check_homogeneity <- function(x, data = NULL, ...) { size_line, alpha_level = 0.2, theme_style = theme_lucid, + base_size = 10, colors = unname(social_colors(c("green", "blue", "red"))), dot_alpha_level = 0.8, show_dots = TRUE) { @@ -164,7 +165,7 @@ plot.see_check_homogeneity <- function(x, data = NULL, ...) { x = "Fitted values" ) + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) diff --git a/R/plot.check_model.R b/R/plot.check_model.R index fd24c6599..eb5e101c2 100644 --- a/R/plot.check_model.R +++ b/R/plot.check_model.R @@ -34,6 +34,7 @@ plot.see_check_model <- function(x, size_line <- attr(x, "line_size") show_labels <- attr(x, "show_labels") %||% TRUE size_text <- attr(x, "text_size") + base_size <- attr(x, "base_size") alpha_level <- attr(x, "alpha") dot_alpha_level <- attr(x, "dot_alpha") show_dots <- attr(x, "show_dots") @@ -74,6 +75,10 @@ plot.see_check_model <- function(x, dot_alpha_level <- 0.8 } + if (is.null(base_size)) { + base_size <- 10 + } + if (is.null(check)) { check <- "all" } @@ -88,6 +93,7 @@ plot.see_check_model <- function(x, style = style, size_line = size_line, size_point = size_point, + base_size = base_size, type = type, check_model = TRUE, adjust_legend = TRUE, @@ -102,6 +108,7 @@ plot.see_check_model <- function(x, size_line, alpha_level, theme_style = style, + base_size = base_size, colors = colors, dot_alpha_level = dot_alpha_level, show_dots = show_dots @@ -113,6 +120,7 @@ plot.see_check_model <- function(x, p$BINNED_RESID <- plot.see_binned_residuals( x$BINNED_RESID, style = style, + base_size = base_size, colors = colors[c(2, 3, 1)], adjust_legend = TRUE, check_model = TRUE, @@ -124,6 +132,7 @@ plot.see_check_model <- function(x, p$OVERDISPERSION <- .plot_diag_overdispersion( x$OVERDISPERSION, style = style, + base_size = base_size, colors = colors[c(1, 2)], size_line = size_line, type = overdisp_type @@ -137,6 +146,7 @@ plot.see_check_model <- function(x, size_line, alpha_level, theme_style = style, + base_size = base_size, colors = colors, dot_alpha_level = dot_alpha_level, show_dots = show_dots @@ -151,6 +161,7 @@ plot.see_check_model <- function(x, size_line = size_line, size_point = size_point, theme_style = style, + base_size = base_size, colors = colors, dot_alpha_level = dot_alpha_level, show_dots = show_dots @@ -163,6 +174,7 @@ plot.see_check_model <- function(x, size_point = 1.5 * size_point, size_line = size_line, theme_style = style, + base_size = base_size, colors = colors, ci_data = attributes(x$VIF)$CI, is_check_model = TRUE @@ -179,7 +191,8 @@ plot.see_check_model <- function(x, dot_alpha = dot_alpha_level, colors = colors, detrend = detrend, - style = style + style = style, + base_size = base_size ) } else { p$QQ <- .plot_diag_qq( @@ -189,6 +202,7 @@ plot.see_check_model <- function(x, alpha_level = alpha_level, detrend = detrend, theme_style = style, + base_size = base_size, colors = colors, dot_alpha_level = dot_alpha_level, show_dots = TRUE, # qq-plots w/o dots makes no sense @@ -204,6 +218,7 @@ plot.see_check_model <- function(x, size_line, alpha_level = alpha_level, theme_style = style, + base_size = base_size, colors = colors ) } @@ -215,6 +230,7 @@ plot.see_check_model <- function(x, size_line, alpha_level = alpha_level, theme_style = style, + base_size = base_size, colors = colors, dot_alpha_level = dot_alpha_level, show_dots = TRUE # qq-plots w/o dots makes no sense @@ -240,6 +256,7 @@ plot.see_check_model <- function(x, size_line, alpha_level = 0.2, theme_style = theme_lucid, + base_size = 10, colors = unname(social_colors(c("green", "blue", "red"))), dot_alpha_level = 0.8, show_dots = TRUE) { @@ -271,7 +288,7 @@ plot.see_check_model <- function(x, subtitle = "Reference line should be flat and horizontal" ) + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) diff --git a/R/plot.check_normality.R b/R/plot.check_normality.R index 52536f054..abdd20e0d 100644 --- a/R/plot.check_normality.R +++ b/R/plot.check_normality.R @@ -19,6 +19,7 @@ #' be one of `"pointwise"` or `"boot"` for pointwise confidence bands, or #' `"ks"` or `"ts"` for simultaneous testing. See `qqplotr::stat_qq_band()` #' for details. +#' @param base_size Base font size for plots. #' @inheritParams data_plot #' @inheritParams plot.see_bayesfactor_parameters #' @@ -44,6 +45,7 @@ plot.see_check_normality <- function(x, size_point = 2, alpha = 0.2, dot_alpha = 0.8, + base_size = 10, colors = c("#3aaf85", "#1b6ca8"), detrend = TRUE, method = "ell", @@ -91,6 +93,7 @@ plot.see_check_normality <- function(x, dot_alpha = dot_alpha, colors = colors, detrend = detrend, + base_size = base_size, transform = stats::qnorm, ... )) @@ -128,7 +131,7 @@ plot.see_check_normality <- function(x, mean(r), stats::sd(r) ) - .plot_diag_norm(dat, size_line = size_line) + .plot_diag_norm(dat, size_line = size_line, alpha_level = alpha, base_size = base_size) } else if (type == "pp") { x <- suppressMessages(sort(stats::residuals(model), na.last = NA)) dat <- data.frame(res = x) @@ -136,6 +139,7 @@ plot.see_check_normality <- function(x, dat, size_point = size_point, size_line = size_line, + base_size = base_size, alpha_level = alpha, detrend = detrend, dot_alpha_level = dot_alpha, @@ -152,6 +156,7 @@ plot.see_check_normality <- function(x, size_line, alpha_level = 0.2, theme_style = theme_lucid, + base_size = 10, colors = unname(social_colors(c("green", "blue", "red")))) { ggplot2::ggplot(x, ggplot2::aes(x = .data$x)) + ggplot2::geom_ribbon( @@ -174,7 +179,7 @@ plot.see_check_normality <- function(x, subtitle = "Distribution should be close to the normal curve" ) + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) + @@ -191,6 +196,7 @@ plot.see_check_normality <- function(x, detrend = FALSE, method = "ell", theme_style = theme_lucid, + base_size = 10, colors = unname(social_colors(c("green", "blue", "red"))), dot_alpha_level = 0.8, show_dots = TRUE, @@ -293,7 +299,7 @@ plot.see_check_normality <- function(x, x = "Standard Normal Distribution Quantiles" ) + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) @@ -309,6 +315,7 @@ plot.see_check_normality <- function(x, detrend = FALSE, method = "ell", theme_style = theme_lucid, + base_size = 10, colors = unname(social_colors(c("green", "blue", "red"))), dot_alpha_level = 0.8) { if (requireNamespace("qqplotr", quietly = TRUE)) { @@ -361,7 +368,7 @@ plot.see_check_normality <- function(x, x = "Standard Normal Cumulative Probability" ) + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) @@ -376,6 +383,7 @@ plot.see_check_normality <- function(x, panel = TRUE, alpha_level = 0.2, theme_style = theme_lucid, + base_size = 10, colors = unname(social_colors(c("green", "blue", "red"))), dot_alpha_level = 0.8, show_dots = TRUE) { @@ -402,7 +410,7 @@ plot.see_check_normality <- function(x, alpha = dot_alpha_level ) + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) diff --git a/R/plot.check_outliers_new.R b/R/plot.check_outliers_new.R index 1ac6f132e..1571f947c 100644 --- a/R/plot.check_outliers_new.R +++ b/R/plot.check_outliers_new.R @@ -7,6 +7,7 @@ size_point = 2, size_text = NULL, theme_style = theme_lucid, + base_size = 10, colors = unname(social_colors(c("green", "blue grey", "red"))), dot_alpha_level = 0.8, show_dots = TRUE) { @@ -48,7 +49,8 @@ method = "loess", na.rm = na.rm, se = FALSE, - color = colors[1] + color = colors[1], + linewidth = size_line ) + scale_colour_manual(values = c(OK = colors[2], Influential = colors[3])) + (if (isTRUE(show_labels)) { @@ -134,7 +136,7 @@ p <- p + .cook_lines + - theme_style(base_size = 10, plot.title.space = 3, axis.title.space = 5) + + theme_style(base_size = base_size, plot.title.space = 3, axis.title.space = 5) + guides(colour = "none", text = "none") } diff --git a/R/plot.check_overdisp.R b/R/plot.check_overdisp.R index dda33f24b..e8b6711f2 100644 --- a/R/plot.check_overdisp.R +++ b/R/plot.check_overdisp.R @@ -16,6 +16,7 @@ plot.see_check_overdisp <- function(x, .plot_diag_overdispersion <- function(x, theme_style = theme_lucid, + base_size = 10, colors = c("#3aaf85", "#1b6ca8"), size_line = 0.8, type = 1, @@ -32,7 +33,7 @@ plot.see_check_overdisp <- function(x, y = "Residual variance" ) + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) @@ -52,7 +53,7 @@ plot.see_check_overdisp <- function(x, y = "Standardized resiuduals" ) + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) diff --git a/R/plot.check_predictions.R b/R/plot.check_predictions.R index 62ce2d5ae..780fe8173 100644 --- a/R/plot.check_predictions.R +++ b/R/plot.check_predictions.R @@ -127,6 +127,7 @@ plot.see_performance_pp_check <- function(x, line_alpha = 0.15, size_bar = 0.7, style = theme_lucid, + base_size = 10, colors = unname(social_colors(c("green", "blue"))), type = c("density", "discrete_dots", "discrete_interval", "discrete_both"), x_limits = NULL, @@ -151,6 +152,7 @@ plot.see_performance_pp_check <- function(x, size_point, line_alpha, theme_style = style, + base_size = base_size, colors = colors, type = type, x_limits = x_limits, @@ -172,6 +174,7 @@ plot.see_performance_pp_check <- function(x, size_point, line_alpha, theme_style, + base_size = 10, colors, type = "density", x_limits = NULL, @@ -204,7 +207,7 @@ plot.see_performance_pp_check <- function(x, dots <- list(...) if (isTRUE(dots[["check_model"]])) { out <- out + theme_style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) diff --git a/R/plot.performance_simres.R b/R/plot.performance_simres.R index dfe488cf7..5bf7d0830 100644 --- a/R/plot.performance_simres.R +++ b/R/plot.performance_simres.R @@ -39,6 +39,7 @@ plot.see_performance_simres <- function(x, detrend = FALSE, transform = NULL, style = theme_lucid, + base_size = 10, ...) { # need DHARMa to be installed insight::check_if_installed("DHARMa") @@ -144,7 +145,7 @@ plot.see_performance_simres <- function(x, y = y_lab ) + style( - base_size = 10, + base_size = base_size, plot.title.space = 3, axis.title.space = 5 ) diff --git a/man/plot.see_check_collinearity.Rd b/man/plot.see_check_collinearity.Rd index 5fcc13c51..1de59b763 100644 --- a/man/plot.see_check_collinearity.Rd +++ b/man/plot.see_check_collinearity.Rd @@ -10,6 +10,7 @@ colors = c("#3aaf85", "#1b6ca8", "#cd201f"), size_point = 3.5, size_line = 0.8, + base_size = 10, ... ) } @@ -26,6 +27,8 @@ hex-format) for points and line.} \item{size_line}{Numeric value specifying size of line geoms.} +\item{base_size}{Base font size for plots.} + \item{...}{Arguments passed to or from other methods.} } \value{ diff --git a/man/plot.see_check_heteroscedasticity.Rd b/man/plot.see_check_heteroscedasticity.Rd index 2bef7ecaf..35575d286 100644 --- a/man/plot.see_check_heteroscedasticity.Rd +++ b/man/plot.see_check_heteroscedasticity.Rd @@ -4,7 +4,7 @@ \alias{plot.see_check_heteroscedasticity} \title{Plot method for (non-)constant error variance checks} \usage{ -\method{plot}{see_check_heteroscedasticity}(x, data = NULL, ...) +\method{plot}{see_check_heteroscedasticity}(x, data = NULL, size_point = 2, size_line = 0.8, base_size = 10, ...) } \arguments{ \item{x}{An object.} @@ -12,6 +12,12 @@ \item{data}{The original data used to create this object. Can be a statistical model.} +\item{size_point}{Numeric specifying size of point-geoms.} + +\item{size_line}{Numeric value specifying size of line geoms.} + +\item{base_size}{Base font size for plots.} + \item{...}{Arguments passed to or from other methods.} } \value{ diff --git a/man/plot.see_check_normality.Rd b/man/plot.see_check_normality.Rd index aa80c71ae..e95dbe292 100644 --- a/man/plot.see_check_normality.Rd +++ b/man/plot.see_check_normality.Rd @@ -12,6 +12,7 @@ size_point = 2, alpha = 0.2, dot_alpha = 0.8, + base_size = 10, colors = c("#3aaf85", "#1b6ca8"), detrend = TRUE, method = "ell", @@ -37,6 +38,8 @@ statistical model.} \item{dot_alpha}{Numeric value specifying alpha level of the point geoms.} +\item{base_size}{Base font size for plots.} + \item{colors}{Character vector of length two, indicating the colors (in hex-format) for points and line.} diff --git a/man/plot.see_performance_simres.Rd b/man/plot.see_performance_simres.Rd index f19928f72..3028a6c58 100644 --- a/man/plot.see_performance_simres.Rd +++ b/man/plot.see_performance_simres.Rd @@ -14,6 +14,7 @@ detrend = FALSE, transform = NULL, style = theme_lucid, + base_size = 10, ... ) } @@ -40,6 +41,8 @@ See argument \code{quantileFuntion} in \code{?DHARMa:::residuals.DHARMa} for mor \item{style}{A ggplot2-theme.} +\item{base_size}{Base font size for plots.} + \item{...}{Arguments passed to or from other methods.} } \value{ diff --git a/man/print.see_performance_pp_check.Rd b/man/print.see_performance_pp_check.Rd index 0960fbbd3..145105781 100644 --- a/man/print.see_performance_pp_check.Rd +++ b/man/print.see_performance_pp_check.Rd @@ -25,6 +25,7 @@ line_alpha = 0.15, size_bar = 0.7, style = theme_lucid, + base_size = 10, colors = unname(social_colors(c("green", "blue"))), type = c("density", "discrete_dots", "discrete_interval", "discrete_both"), x_limits = NULL, @@ -56,6 +57,8 @@ or ordinal etc. - outcomes).} If not \code{NULL}, will zoom in the x-axis to the specified limits.} \item{...}{Arguments passed to or from other methods.} + +\item{base_size}{Base font size for plots.} } \value{ A ggplot2-object. diff --git a/tests/testthat/_snaps/check_model/check-model-works-for-lm.svg b/tests/testthat/_snaps/check_model/check-model-works-for-lm.svg new file mode 100644 index 000000000..a6b0b1114 --- /dev/null +++ b/tests/testthat/_snaps/check_model/check-model-works-for-lm.svg @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2 +-1 +0 +1 +2 + +-2 +-1 +0 +1 +2 +Standard Normal Distribution Quantiles +Sample Quantile Deviations +Dots should fall along the line +Normality of Residuals + + diff --git a/tests/testthat/test-check_model.R b/tests/testthat/test-check_model.R index ea931438b..88729b64d 100644 --- a/tests/testthat/test-check_model.R +++ b/tests/testthat/test-check_model.R @@ -111,3 +111,18 @@ test_that("`check_model()` works if convergence issues", { x <- performance::check_model(m) expect_s3_class(x, "check_model") }) + + + +test_that("`check_model()` works if convergence issues", { + skip_on_cran() + skip_if_not_installed("performance") + data(mtcars) + m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars) + set.seed(123) + x <- performance::check_model(m) + vdiffr::expect_doppelganger( + title = "check_model works for lm", + fig = plot(x) + ) +})