Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow more arguments to tweak plots #333

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

if (isTRUE(dots[["check_model"]])) {
p <- p + theme_style(
base_size = 10,
base_size = base_size,

Check warning on line 109 in R/plot.binned_residuals.R

View check run for this annotation

Codecov / codecov/patch

R/plot.binned_residuals.R#L109

Added line #L109 was not covered by tests
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,10 +4,11 @@
#' `performance::check_heteroscedasticity()` function.
#'
#' @inheritParams data_plot
#' @inheritParams plot.see_check_normality
#'
#' @return A ggplot2-object.
#'
#' @seealso See also the vignette about [`check_model()`](https://easystats.github.io/performance/articles/check_model.html).

Check warning on line 11 in R/plot.check_heteroscedasticity.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_heteroscedasticity.R,line=11,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.

Check warning on line 11 in R/plot.check_heteroscedasticity.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_heteroscedasticity.R,line=11,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
#'
#' @examples
#' m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)
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 @@
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 @@ -9,7 +9,7 @@
#'
#' @return A ggplot2-object.
#'
#' @seealso See also the vignette about [`check_model()`](https://easystats.github.io/performance/articles/check_model.html).

Check warning on line 12 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_model.R,line=12,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.

Check warning on line 12 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_model.R,line=12,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
#'
#' @examplesIf require("patchwork")
#' library(performance)
Expand All @@ -18,7 +18,7 @@
#' plot(check_model(model))
#'
#' @export
plot.see_check_model <- function(x,

Check warning on line 21 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_model.R,line=21,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 80 to at most 40.

Check warning on line 21 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_model.R,line=21,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 80 to at most 40.
style = theme_lucid,
colors = NULL,
type = c("density", "discrete_dots", "discrete_interval", "discrete_both"),
Expand All @@ -34,6 +34,7 @@
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 All @@ -43,7 +44,7 @@
plot_type <- attr(x, "type")
model_class <- attr(x, "model_class")

if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) {

Check warning on line 47 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_model.R,line=47,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 131 characters.

Check warning on line 47 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_model.R,line=47,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 131 characters.
type <- plot_type
} else {
type <- match.arg(type)
Expand Down Expand Up @@ -74,6 +75,10 @@
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 @@
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 @@
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 @@
p$BINNED_RESID <- plot.see_binned_residuals(
x$BINNED_RESID,
style = style,
base_size = base_size,

Check warning on line 123 in R/plot.check_model.R

View check run for this annotation

Codecov / codecov/patch

R/plot.check_model.R#L123

Added line #L123 was not covered by tests
colors = colors[c(2, 3, 1)],
adjust_legend = TRUE,
check_model = TRUE,
Expand All @@ -124,6 +132,7 @@
p$OVERDISPERSION <- .plot_diag_overdispersion(
x$OVERDISPERSION,
style = style,
base_size = base_size,

Check warning on line 135 in R/plot.check_model.R

View check run for this annotation

Codecov / codecov/patch

R/plot.check_model.R#L135

Added line #L135 was not covered by tests
colors = colors[c(1, 2)],
size_line = size_line,
type = overdisp_type
Expand All @@ -137,6 +146,7 @@
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 @@
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 @@
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 @@
dot_alpha = dot_alpha_level,
colors = colors,
detrend = detrend,
style = style
style = style,
base_size = base_size

Check warning on line 195 in R/plot.check_model.R

View check run for this annotation

Codecov / codecov/patch

R/plot.check_model.R#L194-L195

Added lines #L194 - L195 were not covered by tests
)
} else {
p$QQ <- .plot_diag_qq(
Expand All @@ -189,6 +202,7 @@
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 @@
size_line,
alpha_level = alpha_level,
theme_style = style,
base_size = base_size,

Check warning on line 221 in R/plot.check_model.R

View check run for this annotation

Codecov / codecov/patch

R/plot.check_model.R#L221

Added line #L221 was not covered by tests
colors = colors
)
}
Expand All @@ -215,6 +230,7 @@
size_line,
alpha_level = alpha_level,
theme_style = style,
base_size = base_size,

Check warning on line 233 in R/plot.check_model.R

View check run for this annotation

Codecov / codecov/patch

R/plot.check_model.R#L233

Added line #L233 was not covered by tests
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 @@
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 @@
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,12 +19,13 @@
#' 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
#'
#' @return A ggplot2-object.
#'
#' @seealso See also the vignette about [`check_model()`](https://easystats.github.io/performance/articles/check_model.html).

Check warning on line 28 in R/plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_normality.R,line=28,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.

Check warning on line 28 in R/plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_normality.R,line=28,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
#'
#' @examples
#' library(performance)
Expand All @@ -44,6 +45,7 @@
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 @@
dot_alpha = dot_alpha,
colors = colors,
detrend = detrend,
base_size = base_size,

Check warning on line 96 in R/plot.check_normality.R

View check run for this annotation

Codecov / codecov/patch

R/plot.check_normality.R#L96

Added line #L96 was not covered by tests
transform = stats::qnorm,
...
))
Expand Down Expand Up @@ -128,14 +131,15 @@
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)

Check warning on line 134 in R/plot.check_normality.R

View check run for this annotation

Codecov / codecov/patch

R/plot.check_normality.R#L134

Added line #L134 was not covered by tests
} 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 @@
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 @@
subtitle = "Distribution should be close to the normal curve"
) +
theme_style(
base_size = 10,
base_size = base_size,

Check warning on line 182 in R/plot.check_normality.R

View check run for this annotation

Codecov / codecov/patch

R/plot.check_normality.R#L182

Added line #L182 was not covered by tests
plot.title.space = 3,
axis.title.space = 5
) +
Expand All @@ -191,6 +196,7 @@
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 @@ -264,7 +270,7 @@
)
},
ggplot2::geom_qq(
mapping = if (detrend) ggplot2::aes(y = ggplot2::after_stat(.data$sample) - ggplot2::after_stat(.data$theoretical)),

Check warning on line 273 in R/plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_normality.R,line=273,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 124 characters.

Check warning on line 273 in R/plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_normality.R,line=273,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 124 characters.
shape = 16,
na.rm = TRUE,
stroke = 0,
Expand Down Expand Up @@ -293,7 +299,7 @@
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 @@
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 @@
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 @@
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 @@
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
Loading