diff --git a/DESCRIPTION b/DESCRIPTION index d093ea0e31..585a51285a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,7 +38,6 @@ Imports: gtable (>= 0.1.1), isoband, lifecycle (> 1.0.1), - MASS, rlang (>= 1.1.0), scales (>= 1.3.0), stats, @@ -53,6 +52,7 @@ Suggests: knitr, mapproj, maps, + MASS, mgcv, multcomp, munsell, diff --git a/NEWS.md b/NEWS.md index 9d08380189..0eab137d09 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggplot2 (development version) +* `geom_errorbarh()` is deprecated in favour of + `geom_errorbar(orientation = "y")` (@teunbrand, #5961). * `geom_contour()` should be able to recognise a rotated grid of points (@teunbrand, #4320) * `geom_boxplot()` gains additional arguments to style the colour, linetype and diff --git a/R/stat-density-2d.R b/R/stat-density-2d.R index 3fd6cf60ee..d8bbfed57b 100644 --- a/R/stat-density-2d.R +++ b/R/stat-density-2d.R @@ -138,6 +138,7 @@ StatDensity2d <- ggproto("StatDensity2d", Stat, contour_type = "lines", compute_layer = function(self, data, params, layout) { + check_installed("MASS", reason = "for calculating 2D density.") # first run the regular layer calculation to infer densities data <- ggproto_parent(Stat, self)$compute_layer(data, params, layout) diff --git a/R/stat-ellipse.R b/R/stat-ellipse.R index 7404e9eed6..5d1f41dd55 100644 --- a/R/stat-ellipse.R +++ b/R/stat-ellipse.R @@ -77,6 +77,14 @@ stat_ellipse <- function(mapping = NULL, data = NULL, StatEllipse <- ggproto("StatEllipse", Stat, required_aes = c("x", "y"), + setup_params = function(data, params) { + params$type <- params$type %||% "t" + if (identical(params$type, "t")) { + check_installed("MASS", "for calculating ellipses with `type = \"t\"`.") + } + params + }, + compute_group = function(data, scales, type = "t", level = 0.95, segments = 51, na.rm = FALSE) { calculate_ellipse(data = data, vars = c("x", "y"), type = type, diff --git a/R/stat-qq.R b/R/stat-qq.R index dc3762dacd..4ffab00320 100644 --- a/R/stat-qq.R +++ b/R/stat-qq.R @@ -32,8 +32,12 @@ #' p <- ggplot(df, aes(sample = y)) #' p + stat_qq() + stat_qq_line() #' -#' # Use fitdistr from MASS to estimate distribution params -#' params <- as.list(MASS::fitdistr(df$y, "t")$estimate) +#' # Use fitdistr from MASS to estimate distribution params: +#' # if (requireNamespace("MASS", quietly = TRUE)) { +#' # params <- as.list(MASS::fitdistr(df$y, "t")$estimate) +#' # } +#' # Here, we use pre-computed params +#' params <- list(m = -0.02505057194115, s = 1.122568610124, df = 6.63842653897) #' ggplot(df, aes(sample = y)) + #' stat_qq(distribution = qt, dparams = params["df"]) + #' stat_qq_line(distribution = qt, dparams = params["df"]) diff --git a/man/geom_qq.Rd b/man/geom_qq.Rd index d450b3d948..d6bedf3427 100644 --- a/man/geom_qq.Rd +++ b/man/geom_qq.Rd @@ -214,8 +214,12 @@ df <- data.frame(y = rt(200, df = 5)) p <- ggplot(df, aes(sample = y)) p + stat_qq() + stat_qq_line() -# Use fitdistr from MASS to estimate distribution params -params <- as.list(MASS::fitdistr(df$y, "t")$estimate) +# Use fitdistr from MASS to estimate distribution params: +# if (requireNamespace("MASS", quietly = TRUE)) { +# params <- as.list(MASS::fitdistr(df$y, "t")$estimate) +# } +# Here, we use pre-computed params +params <- list(m = -0.02505057194115, s = 1.122568610124, df = 6.63842653897) ggplot(df, aes(sample = y)) + stat_qq(distribution = qt, dparams = params["df"]) + stat_qq_line(distribution = qt, dparams = params["df"]) diff --git a/tests/testthat/test-stat-density2d.R b/tests/testthat/test-stat-density2d.R index 2ecd50a8cb..b5c41efd7d 100644 --- a/tests/testthat/test-stat-density2d.R +++ b/tests/testthat/test-stat-density2d.R @@ -1,3 +1,5 @@ +skip_if_not_installed("MASS") + test_that("uses scale limits, not data limits", { base <- ggplot(mtcars, aes(wt, mpg)) + stat_density_2d() + diff --git a/tests/testthat/test-stat-ellipsis.R b/tests/testthat/test-stat-ellipsis.R index 0c4406f95c..7615091376 100644 --- a/tests/testthat/test-stat-ellipsis.R +++ b/tests/testthat/test-stat-ellipsis.R @@ -1,3 +1,5 @@ +skip_if_not_installed("MASS") + test_that("stat_ellipsis returns correct data format", { n_seg <- 40 d <- data_frame(x = c(1, 1, 4, 4, 4, 3, 3, 1), y = c(1:4, 1:4), id = rep(1:2, each = 4))