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

spurious(?) viewport-too-small error with new ggplot2 version 3.5.0 #328

Merged
merged 3 commits into from
Mar 4, 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.2.3
Version: 0.8.2.4
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
4 changes: 4 additions & 0 deletions R/plot.check_heteroscedasticity.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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 10 in R/plot.check_heteroscedasticity.R

View workflow job for this annotation

GitHub Actions / lint / lint

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

Check warning on line 10 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=10,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
#'
#' @examplesIf require("performance")
#' m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)
Expand Down Expand Up @@ -39,6 +39,10 @@
stats::rstandard(model)
},
error = function(e) {
# debugging
if (getOption("easystats_erros", FALSE)) {
insight::format_error(e$message)

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

View check run for this annotation

Codecov / codecov/patch

R/plot.check_heteroscedasticity.R#L43-L44

Added lines #L43 - L44 were not covered by tests
}
NULL
}
)
Expand Down
32 changes: 15 additions & 17 deletions R/plot.estimate_density.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# summary
split_columns <- intersect(c("Parameter", "Effects", "Component"), colnames(dataplot))
datasplit <- split(dataplot, dataplot[split_columns])
summary <- do.call(rbind, insight::compact_list(lapply(datasplit, function(i) {
my_summary <- do.call(rbind, insight::compact_list(lapply(datasplit, function(i) {
if (length(i$x) > 0L) {
Estimate <- as.numeric(bayestestR::point_estimate(i$x, centrality = centrality))
CI <- as.numeric(bayestestR::ci(i$x, ci = ci))
Expand All @@ -46,10 +46,10 @@
out
})))

summary$Parameter <- factor(summary$Parameter)
summary$Parameter <- factor(summary$Parameter, levels = levels(dataplot$Parameter))
my_summary$Parameter <- factor(my_summary$Parameter)
my_summary$Parameter <- factor(my_summary$Parameter, levels = levels(dataplot$Parameter))

attr(dataplot, "summary") <- summary
attr(dataplot, "summary") <- my_summary
attr(dataplot, "info") <- list(
xlab = "Values",
ylab = "Density",
Expand Down Expand Up @@ -112,9 +112,7 @@
...) {
# save model for later use
model <- tryCatch(
{
.retrieve_data(x)
},
.retrieve_data(x),
error = function(e) {
priors <- FALSE
NULL
Expand All @@ -139,7 +137,7 @@
params <- unique(x$y)

# get labels
labels <- .clean_parameter_names(x$Parameter, grid = !is.null(n_columns))
parameter_labels <- .clean_parameter_names(x$Parameter, grid = !is.null(n_columns))

# remove intercept from output, if requested
x <- .remove_intercept(x, show_intercept = show_intercept)
Expand All @@ -148,7 +146,7 @@
p <- ggplot(x, aes(x = .data$x, y = .data$y, color = .data$Parameter)) +
geom_line(linewidth = size_line) +
add_plot_attributes(x) +
scale_color_flat(labels = labels)
scale_color_flat(labels = parameter_labels)
} else {
p <- ggplot(x, aes(x = .data$x, y = .data$Parameter, height = .data$y))

Expand Down Expand Up @@ -184,13 +182,13 @@
scale_color_manual(values = unname(social_colors("grey")))
}

summary <- attributes(x)$summary
summary <- .remove_intercept(summary, show_intercept = show_intercept)
summary$y <- NA
my_summary <- attributes(x)$summary
my_summary <- .remove_intercept(my_summary, show_intercept = show_intercept)
my_summary$y <- NA

Check warning on line 187 in R/plot.estimate_density.R

View check run for this annotation

Codecov / codecov/patch

R/plot.estimate_density.R#L185-L187

Added lines #L185 - L187 were not covered by tests

p <- p +
geom_errorbarh(
data = summary,
data = my_summary,

Check warning on line 191 in R/plot.estimate_density.R

View check run for this annotation

Codecov / codecov/patch

R/plot.estimate_density.R#L191

Added line #L191 was not covered by tests
mapping = aes(
xmin = .data$CI_low,
xmax = .data$CI_high,
Expand All @@ -199,7 +197,7 @@
linewidth = size_line
) +
geom_point(
data = summary,
data = my_summary,

Check warning on line 200 in R/plot.estimate_density.R

View check run for this annotation

Codecov / codecov/patch

R/plot.estimate_density.R#L200

Added line #L200 was not covered by tests
mapping = aes(x = .data$x, color = "Posterior"),
size = size_point,
fill = "white",
Expand All @@ -213,7 +211,7 @@
if (length(unique(x$Parameter)) == 1 || isTRUE(stack)) {
p <- p + scale_y_continuous(breaks = NULL, labels = NULL)
} else {
p <- p + scale_y_discrete(labels = labels)
p <- p + scale_y_discrete(labels = parameter_labels)

Check warning on line 214 in R/plot.estimate_density.R

View check run for this annotation

Codecov / codecov/patch

R/plot.estimate_density.R#L214

Added line #L214 was not covered by tests
}


Expand Down Expand Up @@ -252,7 +250,7 @@
size_line = 0.9,
...) {
x$Parameter <- factor(x$Parameter, levels = rev(unique(x$Parameter)))
labels <- stats::setNames(levels(x$Parameter), levels(x$Parameter))
parameter_labels <- stats::setNames(levels(x$Parameter), levels(x$Parameter))

Check warning on line 253 in R/plot.estimate_density.R

View check run for this annotation

Codecov / codecov/patch

R/plot.estimate_density.R#L253

Added line #L253 was not covered by tests

if (stack) {
p <- ggplot(x, aes(x = .data$x, y = .data$y, color = .data$Parameter)) +
Expand All @@ -268,7 +266,7 @@
if (length(unique(x$Parameter)) == 1 || isTRUE(stack)) {
p <- p + scale_y_continuous(breaks = NULL, labels = NULL)
} else {
p <- p + scale_y_discrete(labels = labels)
p <- p + scale_y_discrete(labels = parameter_labels)

Check warning on line 269 in R/plot.estimate_density.R

View check run for this annotation

Codecov / codecov/patch

R/plot.estimate_density.R#L269

Added line #L269 was not covered by tests
}

if (length(unique(x$Parameter)) == 1L) {
Expand Down
16 changes: 7 additions & 9 deletions R/plot.point_estimates.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
}

data <- tryCatch(
{
if (!is.null(x$Parameter)) {
data[, x$Parameter, drop = FALSE]
} else {
data
}
if (!is.null(x$Parameter)) {

Check warning on line 23 in R/plot.point_estimates.R

View workflow job for this annotation

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

file=R/plot.point_estimates.R,line=23,col=9,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
data[, x$Parameter, drop = FALSE]
} else {
data

Check warning on line 26 in R/plot.point_estimates.R

View check run for this annotation

Codecov / codecov/patch

R/plot.point_estimates.R#L26

Added line #L26 was not covered by tests
},
error = function(e) {
data
Expand All @@ -36,10 +34,10 @@
if (is.null(centrality)) centrality <- "all"

dataplot <- lapply(colnames(data), function(i) {
dist <- data[[i]]
my_dist <- data[[i]]

pe <- bayestestR::point_estimate(dist, centrality = "all")
dat <- as.data.frame(stats::density(dist, n = 256))
pe <- bayestestR::point_estimate(my_dist, centrality = "all")
dat <- as.data.frame(stats::density(my_dist, n = 256))
dat$group <- i

if (any(centrality %in% c("all", "mean"))) {
Expand Down
10 changes: 7 additions & 3 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@

.safe_print_plots <- function(pw, ...) {
pw_drawn <- tryCatch(print(pw), error = function(e) e)
# for debugging, return original error
if (getOption("easystats_erros", FALSE)) {
insight::format_error(pw_drawn$message)

Check warning on line 104 in R/plots.R

View check run for this annotation

Codecov / codecov/patch

R/plots.R#L103-L104

Added lines #L103 - L104 were not covered by tests
}
if (inherits(pw_drawn, "simpleError")) {
msg_display1 <- "\n- To fix this issue, please make the window larger."
msg_display3 <- "\n- If this still doesn't resolve your problems, you may check whether your apps are rescaled. On Windows, this can be done in the display settings (Start > Settings > System > Display, \"Scale and layout\"). Reduce the scaling and try again."
msg_display4 <- "\n- Finally, you can try to decrease the base font-size of your theme before plotting. Load `library(ggplot2)` and run: `theme_set(theme_classic(base_size = 6))`"
msg_display3 <- "\n- If this still doesn't resolve your problems, you may check whether your apps are rescaled. On Windows, this can be done in the display settings (Start > Settings > System > Display, \"Scale and layout\"). Reduce the scaling and try again." # nolint
msg_display4 <- "\n- Finally, you can try to decrease the base font-size of your theme before plotting. Load `library(ggplot2)` and run: `theme_set(theme_classic(base_size = 6))`" # nolint

Check warning on line 109 in R/plots.R

View check run for this annotation

Codecov / codecov/patch

R/plots.R#L108-L109

Added lines #L108 - L109 were not covered by tests

if (Sys.getenv("RSTUDIO") == "1") {
msg <- "The RStudio 'Plots' window is too small to show this set of plots."
msg_display2 <- "\n- If this doesn't help, try to reset your zoom settings. In RStudio, go to Menu \"View > Actual Size\" and then retry."
msg_display2 <- "\n- If this doesn't help, try to reset your zoom settings. In RStudio, go to Menu \"View > Actual Size\" and then retry." # nolint

Check warning on line 113 in R/plots.R

View check run for this annotation

Codecov / codecov/patch

R/plots.R#L113

Added line #L113 was not covered by tests
} else {
msg <- "The viewport is too small to show this set of plots."
msg_display2 <- "\n- If this doesn't help, try to reset the zoom settings of your IDE and then retry."
Expand Down
Loading