Skip to content

Commit 5651757

Browse files
authored
theme argument of check_model() has no effect. (#426)
Fixes easystats/performance#851
1 parent 3d8a493 commit 5651757

42 files changed

Lines changed: 6381 additions & 5697 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,4 @@ Config/testthat/edition: 3
127127
Config/testthat/parallel: true
128128
Config/Needs/website: easystats/easystatstemplate
129129
Config/rcmdcheck/ignore-inconsequential-notes: true
130+
Remotes: easystats/performance

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
* Daniel Lüdecke is now the main maintainer of the package.
66

7+
* Several `plot()` methods gain a `theme` argument, to control the visual
8+
themes for plots. This is in particular useful for plots that consist of
9+
several single plots, like the one returned by `check_model()`.
10+
711
## Changes
812

913
* `plot()` for `check_model()` now limits the number of data points for models

R/plot.binned_residuals.R

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@ plot.see_binned_residuals <- function(
88
base_size = 10,
99
colors = social_colors(c("blue", "red", "green")),
1010
show_smooth = FALSE,
11-
style = theme_lucid,
11+
theme = NULL,
1212
...
1313
) {
14+
theme <- .set_default_theme(
15+
x,
16+
theme,
17+
base_size,
18+
size_axis_title,
19+
size_title,
20+
default_theme = ggplot2::theme_grey()
21+
)
22+
1423
x$se.lo <- -x$se
1524
if (length(unique(x$group)) > 1L) {
1625
ltitle <- "Within error bounds"
@@ -27,12 +36,6 @@ plot.see_binned_residuals <- function(
2736
show_dots <- isTRUE(dots[["show_dots"]])
2837
}
2938

30-
if (missing(style) && !is.null(attr(x, "theme"))) {
31-
theme_style <- unlist(strsplit(attr(x, "theme"), "::", fixed = TRUE))
32-
style <- get(theme_style[2], asNamespace(theme_style[1]))
33-
}
34-
theme_style <- style
35-
3639
if (is.null(colors) || length(colors) != 3) {
3740
colors <- social_colors(c("blue", "red", "green"))
3841
}
@@ -124,16 +127,7 @@ plot.see_binned_residuals <- function(
124127
)
125128
}
126129

127-
if (isTRUE(dots[["check_model"]])) {
128-
p <- p +
129-
theme_style(
130-
base_size = base_size,
131-
plot.title.space = 3,
132-
axis.title.space = 5,
133-
axis.title.size = size_axis_title,
134-
plot.title.size = size_title
135-
)
136-
}
130+
p <- p + theme
137131

138132
if (isTRUE(dots[["adjust_legend"]])) {
139133
p <- p +

R/plot.check_collinearity.R

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#'
55
#' @inheritParams data_plot
66
#' @inheritParams plot.see_check_normality
7+
#' @inheritParams print.see_performance_pp_check
78
#'
89
#' @return A ggplot2-object.
910
#'
@@ -18,6 +19,7 @@
1819
plot.see_check_collinearity <- function(
1920
x,
2021
data = NULL,
22+
theme = NULL,
2123
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
2224
size_point = 3.5,
2325
linewidth = 0.8,
@@ -56,6 +58,7 @@ plot.see_check_collinearity <- function(
5658
size_title = size_title,
5759
size_axis_title = size_axis_title,
5860
base_size = base_size,
61+
theme = theme,
5962
colors = colors,
6063
ci_data = attributes(x)$CI,
6164
is_check_model = FALSE
@@ -67,14 +70,22 @@ plot.see_check_collinearity <- function(
6770
x,
6871
size_point,
6972
linewidth,
70-
theme_style = theme_lucid,
73+
theme = NULL,
7174
size_title = 12,
7275
size_axis_title = 10,
7376
base_size = 10,
7477
colors = unname(social_colors(c("green", "blue", "red"))),
7578
ci_data = NULL,
7679
is_check_model = FALSE
7780
) {
81+
theme <- .set_default_theme(
82+
x,
83+
theme,
84+
base_size,
85+
size_axis_title,
86+
size_title
87+
)
88+
7889
ylim <- ceiling(max(x$y, na.rm = TRUE))
7990
xlim <- nrow(x)
8091
if (ylim < 10) {
@@ -178,13 +189,7 @@ plot.see_check_collinearity <- function(
178189
aesthetics = c("color", "fill"),
179190
guide = ggplot2::guide_legend(title = NULL)
180191
) +
181-
theme_style(
182-
base_size = base_size,
183-
plot.title.space = 3,
184-
axis.title.space = 5,
185-
plot.title.size = size_title,
186-
axis.title.size = size_axis_title
187-
) +
192+
theme +
188193
ggplot2::scale_y_continuous(
189194
limits = c(1, ylim * 1.15),
190195
oob = scales::oob_squish,

R/plot.check_distribution.R

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,39 @@ plot.see_check_distribution <- function(x, size_point = 2, panel = TRUE, ...) {
4646
# default legend-position
4747
lp <- ifelse(isTRUE(panel), "right", "bottom")
4848

49-
p1 <- ggplot(
49+
p1 <- ggplot2::ggplot(
5050
dat,
51-
aes(
51+
ggplot2::aes(
5252
y = .data$x,
5353
x = .data$y,
5454
colour = .data$group
5555
)
5656
) +
57-
geom_linerange(
58-
aes(xmin = 0, xmax = .data$y),
59-
position = position_dodge(0.4),
57+
ggplot2::geom_linerange(
58+
ggplot2::aes(xmin = 0, xmax = .data$y),
59+
position = ggplot2::position_dodge(0.4),
6060
linewidth = 0.8,
6161
na.rm = TRUE
6262
) +
63-
geom_point(
63+
ggplot2::geom_point(
6464
size = size_point,
65-
position = position_dodge(0.4),
65+
position = ggplot2::position_dodge(0.4),
6666
na.rm = TRUE
6767
) +
68-
labs(
68+
ggplot2::labs(
6969
y = NULL,
7070
x = NULL,
7171
fill = NULL,
7272
colour = NULL,
7373
title = "Predicted Distribution of Residuals and Response"
7474
) +
75-
scale_x_continuous(
75+
ggplot2::scale_x_continuous(
7676
labels = .percents,
7777
expand = c(0, 0),
7878
limits = c(0, max_y)
7979
) +
8080
scale_color_material_d(reverse = TRUE) +
81-
guides(colour = guide_legend(reverse = TRUE)) +
81+
ggplot2::guides(colour = ggplot2::guide_legend(reverse = TRUE)) +
8282
theme_lucid(legend.position = lp)
8383

8484
dat1 <- as.data.frame(stats::density(stats::residuals(model)))
@@ -90,9 +90,9 @@ plot.see_check_distribution <- function(x, size_point = 2, panel = TRUE, ...) {
9090
dat2$x <- round(dat2$x)
9191
}
9292

93-
p2 <- ggplot(dat1, aes(x = .data$x, y = .data$y)) +
94-
geom_line(colour = "#2196F3") +
95-
labs(x = NULL, y = NULL, title = "Density of Residuals") +
93+
p2 <- ggplot2::ggplot(dat1, ggplot2::aes(x = .data$x, y = .data$y)) +
94+
ggplot2::geom_line(colour = "#2196F3") +
95+
ggplot2::labs(x = NULL, y = NULL, title = "Density of Residuals") +
9696
theme_lucid()
9797

9898
# usually, we have an outline for the bars in the same color as the
@@ -106,14 +106,14 @@ plot.see_check_distribution <- function(x, size_point = 2, panel = TRUE, ...) {
106106
bar_color <- theme_lucid()$panel.background$fill
107107
}
108108

109-
p3 <- ggplot(dat2, aes(x = .data$x)) +
110-
geom_histogram(
109+
p3 <- ggplot2::ggplot(dat2, ggplot2::aes(x = .data$x)) +
110+
ggplot2::geom_histogram(
111111
fill = "#f44336",
112112
colour = bar_color,
113113
binwidth = sqrt(length(vars(.data$x))),
114114
na.rm = TRUE
115115
) +
116-
labs(x = NULL, y = NULL, title = "Distribution of Response") +
116+
ggplot2::labs(x = NULL, y = NULL, title = "Distribution of Response") +
117117
theme_lucid()
118118

119119
if (panel) {
@@ -150,26 +150,26 @@ plot.see_check_distribution_numeric <- function(
150150
# default legend-position
151151
lp <- ifelse(isTRUE(panel), "right", "bottom")
152152

153-
p1 <- ggplot(dat, aes(y = .data$x, x = .data$y)) +
154-
geom_linerange(
155-
aes(xmin = 0, xmax = .data$y),
156-
position = position_dodge(0.4),
153+
p1 <- ggplot2::ggplot(dat, ggplot2::aes(y = .data$x, x = .data$y)) +
154+
ggplot2::geom_linerange(
155+
ggplot2::aes(xmin = 0, xmax = .data$y),
156+
position = ggplot2::position_dodge(0.4),
157157
linewidth = 0.8,
158158
na.rm = TRUE
159159
) +
160-
geom_point(
160+
ggplot2::geom_point(
161161
size = size_point,
162-
position = position_dodge(0.4),
162+
position = ggplot2::position_dodge(0.4),
163163
na.rm = TRUE
164164
) +
165-
labs(
165+
ggplot2::labs(
166166
y = NULL,
167167
x = NULL,
168168
fill = NULL,
169169
colour = NULL,
170170
title = "Predicted Distribution of Vector"
171171
) +
172-
scale_x_continuous(
172+
ggplot2::scale_x_continuous(
173173
labels = .percents,
174174
expand = c(0, 0),
175175
limits = c(0, max_y)
@@ -179,18 +179,18 @@ plot.see_check_distribution_numeric <- function(
179179
dat1 <- as.data.frame(stats::density(vec))
180180
dat2 <- data.frame(x = vec, stringsAsFactors = FALSE)
181181

182-
p2 <- ggplot(dat1, aes(x = .data$x, y = .data$y)) +
183-
geom_line() +
184-
labs(x = NULL, y = NULL, title = "Density of Vector") +
182+
p2 <- ggplot2::ggplot(dat1, ggplot2::aes(x = .data$x, y = .data$y)) +
183+
ggplot2::geom_line() +
184+
ggplot2::labs(x = NULL, y = NULL, title = "Density of Vector") +
185185
theme_lucid()
186186

187-
p3 <- ggplot(dat2, aes(x = .data$x)) +
188-
geom_histogram(
187+
p3 <- ggplot2::ggplot(dat2, ggplot2::aes(x = .data$x)) +
188+
ggplot2::geom_histogram(
189189
colour = theme_lucid()$panel.background$fill,
190190
binwidth = sqrt(length(vars(.data$x))),
191191
na.rm = TRUE
192192
) +
193-
labs(x = NULL, y = NULL, title = "Distribution of Vector") +
193+
ggplot2::labs(x = NULL, y = NULL, title = "Distribution of Vector") +
194194
theme_lucid()
195195

196196
if (panel) {

R/plot.check_heteroscedasticity.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#'
66
#' @inheritParams data_plot
77
#' @inheritParams plot.see_check_normality
8+
#' @inheritParams print.see_performance_pp_check
89
#'
910
#' @return A ggplot2-object.
1011
#'
@@ -24,6 +25,7 @@ plot.see_check_heteroscedasticity <- function(
2425
size_title = 12,
2526
size_axis_title = base_size,
2627
base_size = 10,
28+
theme = NULL,
2729
...
2830
) {
2931
if (is.null(data)) {
@@ -85,6 +87,7 @@ plot.see_check_heteroscedasticity <- function(
8587
base_size = base_size,
8688
size_title = size_title,
8789
size_axis_title = size_axis_title,
90+
theme = theme,
8891
...
8992
)
9093
}

R/plot.check_homogeneity.R

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ plot.see_check_homogeneity <- function(x, data = NULL, ...) {
149149
size_point,
150150
linewidth,
151151
alpha_level = 0.2,
152-
theme_style = theme_lucid,
152+
theme = NULL,
153153
size_title = 12,
154154
size_axis_title = 10,
155155
base_size = 10,
@@ -159,6 +159,15 @@ plot.see_check_homogeneity <- function(x, data = NULL, ...) {
159159
maximum_dots = 2000,
160160
...
161161
) {
162+
theme <- .set_default_theme(
163+
x,
164+
theme,
165+
base_size,
166+
size_axis_title,
167+
size_title,
168+
default_theme = ggplot2::theme_grey()
169+
)
170+
162171
# Sample data if too large for performance (issue #420)
163172
x <- .sample_for_plot(x, maximum_dots = maximum_dots, ...)
164173

@@ -188,11 +197,5 @@ plot.see_check_homogeneity <- function(x, data = NULL, ...) {
188197
y = expression(sqrt("|Std. residuals|")),
189198
x = "Fitted values"
190199
) +
191-
theme_style(
192-
base_size = base_size,
193-
plot.title.space = 3,
194-
axis.title.space = 5,
195-
plot.title.size = size_title,
196-
axis.title.size = size_axis_title
197-
)
200+
theme
198201
}

0 commit comments

Comments
 (0)