Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Imports:
gtable (>= 0.1.1),
isoband,
lifecycle (> 1.0.1),
MASS,
mgcv,
rlang (>= 1.1.0),
scales (>= 1.3.0),
Expand All @@ -56,6 +55,7 @@ Suggests:
knitr,
mapproj,
maps,
MASS,
multcomp,
munsell,
nlme,
Expand All @@ -79,7 +79,7 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Collate:
'ggproto.R'
'ggplot-global.R'
Expand Down
1 change: 1 addition & 0 deletions R/stat-density-2d.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions R/stat-ellipse.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions R/stat-qq.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
8 changes: 6 additions & 2 deletions man/geom_qq.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/testthat/test-stat-density2d.R
Original file line number Diff line number Diff line change
@@ -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() +
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-stat-ellipsis.R
Original file line number Diff line number Diff line change
@@ -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))
Expand Down