diff --git a/DESCRIPTION b/DESCRIPTION index 9614222..f7681eb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ Description: Diagnostic plots for optimisation, with a focus on projection pursu License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -URL: https://github.com/huizezhang-sherry/ferrn/ +URL: https://github.com/huizezhang-sherry/ferrn/, https://huizezhang-sherry.github.io/ferrn BugReports: https://github.com/huizezhang-sherry/ferrn/issues Imports: rlang (>= 0.1.2), @@ -34,7 +34,7 @@ Imports: cli, progress, glue, - GpGp, + GpGp RoxygenNote: 7.3.2 Depends: R (>= 2.10) @@ -46,5 +46,5 @@ Suggests: forcats, patchwork, future.apply, - ash + ash, Language: en-GB diff --git a/R/explore-space-tour.R b/R/explore-space-tour.R index 9d8824a..27183f8 100644 --- a/R/explore-space-tour.R +++ b/R/explore-space-tour.R @@ -35,9 +35,11 @@ explore_space_tour <- function(..., axes = "bottomleft") { #' @param axes see [tourr::animate_xy()] #' @param ... other argument passed to \code{tourr::animate_xy()} and \code{prep_space_tour()} #' @examples +#' if (FALSE){ #' explore_space_tour(dplyr::bind_rows(holes_1d_better, holes_1d_geo), #' group = method, palette = botanical_palettes$fern[c(1, 6)] #' ) +#' } #' @rdname explore_space_tour #' @export prep_space_tour <- function(dt, group = NULL, flip = FALSE, n_random = 2000, diff --git a/R/huber-plot.R b/R/huber-plot.R index f6d702e..d42f023 100644 --- a/R/huber-plot.R +++ b/R/huber-plot.R @@ -1,33 +1,50 @@ #' Create Huber plot with ggplot2 #' +#' The Huber plot presents the projection pursuit index values of 2D data in each 1D +#' projection in polar coordinates, corresponding to each projection direction. +#' It offers a simpler illustration of more complex projection from +#' high-dimensional data to lower dimensions in projection pursuit. The +#' function \code{prep_huber()} calculates each component required for the Huber plot +#' (see details), which can then be supplied to various geom layers in ggplot2. +#' +#' @details the \code{prep_huber()} function calculates components required for +#' making the Huber plots. It returns a list including three elements: +#'\describe{ +#' \item{the \code{idx_df} data frame: }{the x/y coordinates of the index value, in polar +#' coordinates. Used for plotting the index value at each projection direction, +#' with the reference circle.} +#' \item{the \code{proj_df} data frame: }{the best 1D projection. Used for plotting +#' the 1D projection in histogram.} +#' \item{the \code{slope} value: }{the slope to plot in the Huber plot to indicate the +#' direction of the best 1D projection.} +#' } #' @inheritParams ggplot2::layer #' @inheritParams ggplot2::geom_path #' @param index a function, the projection pursuit index function, see examples #' @rdname huber #' @export #' @examples -#' 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))) +#' library(ggplot2) +#' library(tourr) +#' library(ash) +#' 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 360a396..160f087 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -2,9 +2,7 @@ url: https://huizezhang-sherry.github.io/ferrn/ template: - params: - bootswatch: cosmo - ganalytics: G-SPC6B94B10 + bootstrap: 5 reference: - title: Main plotting functions @@ -18,6 +16,9 @@ reference: - plot_projection - flip_sign - geom_huber +- title: Calculate projection pursuit index metrics + contents: + - starts_with("calc") - title: Get components desc: > Extracting components from existing data object @@ -47,9 +48,6 @@ reference: contents: - starts_with("boa") - starts_with("holes") -- title: Calculate projection pursuit optimisation properties - contents: - - starts_with("calc") - title: Miscellaneous desc: > Other misc functions diff --git a/docs/404.html b/docs/404.html index bea073c..811556d 100644 --- a/docs/404.html +++ b/docs/404.html @@ -4,7 +4,7 @@ - +