Skip to content

Commit

Permalink
Allow more arguments to tweak plots (#333)
Browse files Browse the repository at this point in the history
* Allow more arguments to tweak plots

* add check

* docs
  • Loading branch information
strengejacke authored Mar 26, 2024
1 parent cddf268 commit 80daa3c
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 21 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/plot.binned_residuals.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#'
#' @export
plot.see_binned_residuals <- function(x,
size_line = 0.7,
size_point = 2.2,
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) {
Expand Down Expand Up @@ -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
)
Expand Down
5 changes: 4 additions & 1 deletion R/plot.check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
) +
Expand Down
5 changes: 3 additions & 2 deletions R/plot.check_heteroscedasticity.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' `performance::check_heteroscedasticity()` function.
#'
#' @inheritParams data_plot
#' @inheritParams plot.see_check_normality
#'
#' @return A ggplot2-object.
#'
Expand All @@ -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 {
Expand Down Expand Up @@ -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, ...)
}


Expand Down
3 changes: 2 additions & 1 deletion R/plot.check_homogeneity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
)
Expand Down
21 changes: 19 additions & 2 deletions R/plot.check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"
}
Expand 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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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
)
}
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
)
Expand Down
18 changes: 13 additions & 5 deletions R/plot.check_normality.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand All @@ -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",
Expand Down Expand Up @@ -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,
...
))
Expand Down Expand Up @@ -128,14 +131,15 @@ 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)
.plot_diag_pp(
dat,
size_point = size_point,
size_line = size_line,
base_size = base_size,
alpha_level = alpha,
detrend = detrend,
dot_alpha_level = dot_alpha,
Expand All @@ -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(
Expand All @@ -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
) +
Expand All @@ -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,
Expand Down Expand Up @@ -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
)
Expand All @@ -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)) {
Expand Down Expand Up @@ -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
)
Expand All @@ -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) {
Expand All @@ -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
)
Expand Down
6 changes: 4 additions & 2 deletions R/plot.check_outliers_new.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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")
}

Expand Down
Loading

0 comments on commit 80daa3c

Please sign in to comment.