From c09930d9a5b848fbbe2fd4bfd203703fc872f04a Mon Sep 17 00:00:00 2001 From: huizezhang-sherry Date: Tue, 10 Sep 2024 15:45:21 -0500 Subject: [PATCH] add ash as sugguest --- DESCRIPTION | 1 + R/huber-plot.R | 38 ++++++++++++++++++++------------------ _pkgdown.yml | 2 +- man/huber.Rd | 38 ++++++++++++++++++++------------------ 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 22c3dbf..9614222 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,4 +46,5 @@ Suggests: forcats, patchwork, future.apply, + ash Language: en-GB diff --git a/R/huber-plot.R b/R/huber-plot.R index 8118c97..f6d702e 100644 --- a/R/huber-plot.R +++ b/R/huber-plot.R @@ -6,26 +6,28 @@ #' @rdname huber #' @export #' @examples -#' library(ggplot2) -#' library(tourr) -#' data(randu) -#' randu_std <- as.data.frame(apply(randu, 2, function(x) (x-mean(x))/sd(x))) -#' randu_std$yz <- sqrt(35)/6*randu_std$y-randu_std$z/6 -#' randu_df <- randu_std[c(1,4)] -#' randu_huber <- prep_huber(randu_df, index = norm_bin(nr = nrow(randu_df))) +#' if (require(ash, quietly = TRUE)) { +#' library(ggplot2) +#' library(tourr) +#' data(randu) +#' randu_std <- as.data.frame(apply(randu, 2, function(x) (x-mean(x))/sd(x))) +#' randu_std$yz <- sqrt(35)/6*randu_std$y-randu_std$z/6 +#' randu_df <- randu_std[c(1,4)] +#' randu_huber <- prep_huber(randu_df, index = norm_bin(nr = nrow(randu_df))) #' -#' ggplot() + -#' geom_huber(data = randu_huber$idx_df, aes(x = x, y = y)) + -#' geom_point(data = randu_df, aes(x = x, y = yz)) + -#' geom_abline(slope = randu_huber$slope, intercept = 0) + -#' theme_huber() + -#' coord_fixed() +#' ggplot() + +#' geom_huber(data = randu_huber$idx_df, aes(x = x, y = y)) + +#' geom_point(data = randu_df, aes(x = x, y = yz)) + +#' geom_abline(slope = randu_huber$slope, intercept = 0) + +#' theme_huber() + +#' coord_fixed() #' -#' ggplot(randu_huber$proj_df, aes(x = x)) + -#' geom_histogram(breaks = seq(-2.2, 2.4, 0.12)) + -#' xlab("") + ylab("") + -#' theme_bw() + -#' theme(axis.text.y = element_blank()) +#' ggplot(randu_huber$proj_df, aes(x = x)) + +#' geom_histogram(breaks = seq(-2.2, 2.4, 0.12)) + +#' xlab("") + ylab("") + +#' theme_bw() + +#' theme(axis.text.y = element_blank()) +#'} geom_huber <- function(mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., show.legend = NA, inherit.aes = TRUE) { diff --git a/_pkgdown.yml b/_pkgdown.yml index 50911fe..360a396 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -41,7 +41,7 @@ reference: - botanical_pal - starts_with("scale") - theme_fern -- title: In-built data +- title: Data desc: > Simulated example data contents: diff --git a/man/huber.Rd b/man/huber.Rd index 31eafd8..dca6dfa 100644 --- a/man/huber.Rd +++ b/man/huber.Rd @@ -112,24 +112,26 @@ the default plot specification, e.g. \code{\link[ggplot2:borders]{borders()}}.} Create Huber plot with ggplot2 } \examples{ -library(ggplot2) -library(tourr) -data(randu) -randu_std <- as.data.frame(apply(randu, 2, function(x) (x-mean(x))/sd(x))) -randu_std$yz <- sqrt(35)/6*randu_std$y-randu_std$z/6 -randu_df <- randu_std[c(1,4)] -randu_huber <- prep_huber(randu_df, index = norm_bin(nr = nrow(randu_df))) +if (require(ash, quietly = TRUE)) { + library(ggplot2) + library(tourr) + data(randu) + randu_std <- as.data.frame(apply(randu, 2, function(x) (x-mean(x))/sd(x))) + randu_std$yz <- sqrt(35)/6*randu_std$y-randu_std$z/6 + randu_df <- randu_std[c(1,4)] + randu_huber <- prep_huber(randu_df, index = norm_bin(nr = nrow(randu_df))) -ggplot() + - geom_huber(data = randu_huber$idx_df, aes(x = x, y = y)) + - geom_point(data = randu_df, aes(x = x, y = yz)) + - geom_abline(slope = randu_huber$slope, intercept = 0) + - theme_huber() + - coord_fixed() + ggplot() + + geom_huber(data = randu_huber$idx_df, aes(x = x, y = y)) + + geom_point(data = randu_df, aes(x = x, y = yz)) + + geom_abline(slope = randu_huber$slope, intercept = 0) + + theme_huber() + + coord_fixed() -ggplot(randu_huber$proj_df, aes(x = x)) + - geom_histogram(breaks = seq(-2.2, 2.4, 0.12)) + - xlab("") + ylab("") + - theme_bw() + - theme(axis.text.y = element_blank()) + ggplot(randu_huber$proj_df, aes(x = x)) + + geom_histogram(breaks = seq(-2.2, 2.4, 0.12)) + + xlab("") + ylab("") + + theme_bw() + + theme(axis.text.y = element_blank()) +} }