Skip to content

Commit

Permalink
documentation for the huber plot
Browse files Browse the repository at this point in the history
  • Loading branch information
huizezhang-sherry committed Sep 12, 2024
1 parent c09930d commit b2e91b2
Show file tree
Hide file tree
Showing 53 changed files with 1,972 additions and 3,573 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -34,7 +34,7 @@ Imports:
cli,
progress,
glue,
GpGp,
GpGp
RoxygenNote: 7.3.2
Depends:
R (>= 2.10)
Expand All @@ -46,5 +46,5 @@ Suggests:
forcats,
patchwork,
future.apply,
ash
ash,
Language: en-GB
2 changes: 2 additions & 0 deletions R/explore-space-tour.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
57 changes: 37 additions & 20 deletions R/huber-plot.R
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
115 changes: 40 additions & 75 deletions docs/404.html

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

Loading

0 comments on commit b2e91b2

Please sign in to comment.