Skip to content

Commit

Permalink
debug examples following element restriction + adapt density_2d stat …
Browse files Browse the repository at this point in the history
…& geom
  • Loading branch information
corybrunson committed Dec 31, 2024
1 parent 852d823 commit 0a52715
Show file tree
Hide file tree
Showing 23 changed files with 550 additions and 112 deletions.
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export(StatCols)
export(StatColsCenter)
export(StatColsChull)
export(StatColsCone)
export(StatColsDensity2d)
export(StatColsDensity2dFilled)
export(StatColsEllipse)
export(StatColsProjection)
export(StatColsRule)
Expand All @@ -214,6 +216,8 @@ export(StatRows)
export(StatRowsCenter)
export(StatRowsChull)
export(StatRowsCone)
export(StatRowsDensity2d)
export(StatRowsDensity2dFilled)
export(StatRowsEllipse)
export(StatRowsProjection)
export(StatRowsRule)
Expand All @@ -240,6 +244,8 @@ export(draw_key_line)
export(eigen_ord)
export(geom_axis)
export(geom_cols_axis)
export(geom_cols_density_2d)
export(geom_cols_density_2d_filled)
export(geom_cols_interpolation)
export(geom_cols_isoline)
export(geom_cols_label)
Expand All @@ -261,6 +267,8 @@ export(geom_lineranges)
export(geom_origin)
export(geom_pointranges)
export(geom_rows_axis)
export(geom_rows_density_2d)
export(geom_rows_density_2d_filled)
export(geom_rows_interpolation)
export(geom_rows_isoline)
export(geom_rows_label)
Expand Down Expand Up @@ -328,6 +336,8 @@ export(stat_cols)
export(stat_cols_center)
export(stat_cols_chull)
export(stat_cols_cone)
export(stat_cols_density_2d)
export(stat_cols_density_2d_filled)
export(stat_cols_ellipse)
export(stat_cols_projection)
export(stat_cols_rule)
Expand All @@ -341,6 +351,8 @@ export(stat_rows)
export(stat_rows_center)
export(stat_rows_chull)
export(stat_rows_cone)
export(stat_rows_density_2d)
export(stat_rows_density_2d_filled)
export(stat_rows_ellipse)
export(stat_rows_projection)
export(stat_rows_rule)
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ The 'projection' referential stat prepares segment endpoints between `x,y` posit

A new 'rule' statistical transformation computes additional position aesthetics that the 'axis' geom uses to limit and offset axes. The stat is referential and expects a set of functions that compute limits `lower` and `upper` along the axes and `yintercept` and `xintercept` associated with offset axes. The 'axis' geom preprocesses these aesthetics to rule endpoints `xmin,ymin,xmax,ymax` and offset vectors `xend,yend` to force the plotting window to contain the limited axis segments or, if the axes remain lines, the offsets where they are centered.

## standardized and restrictive elements parameter (breaking change)

The `elements` parameter is now standardized across all statistical transformations (through the code generation process) and accepts more restrictive options:
The value is argument-matched to `"active"`, `"score"`, or `"structure"`; these options may expand as additional supplementary elements are introduced.
Moreover, the former default `"all"` is no longer accepted, which forecloses the trick of passing the element type to an aesthetic, e.g. `size = .element == "active"`, as had been used in several examples.

## adapted density stat & geom

Aided by element standardization, the classic `density_2d` statistical transformation and geometric construction are adapted to biplots.
Currently, source code generation does not respect fixed parameters passed to `layer()` by the `stat_*()` and `geom_*()` shortcuts; as a consequence, `contour = TRUE` must be manually passed to `geom_*_density_2d()`.

## scaffold theme

The 'biplot' theme has been renamed 'scaffold', with an alias for backward compatibility.
Expand Down
3 changes: 1 addition & 2 deletions R/stat-projection.r
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#' @export
stat_projection <- function(
mapping = NULL, data = NULL, geom = "segment", position = "identity",
subset = NULL,
referent = NULL,
...,
show.legend = NA, inherit.aes = TRUE
Expand Down Expand Up @@ -71,7 +70,7 @@ StatProjection <- ggproto(
"StatProjection", StatReferent,

compute_group = function(data, scales,
subset = NULL, referent = NULL, na.rm = FALSE) {
referent = NULL, na.rm = FALSE) {

# no referent means no projection
if (is.null(referent) || ! is.data.frame(referent)) return(data.frame())
Expand Down
4 changes: 2 additions & 2 deletions R/stat-referent.r
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
stat_referent <- function(
mapping = NULL, data = NULL,
geom = "blank", position = "identity",
subset = NULL,
referent = NULL,
show.legend = NA,
inherit.aes = TRUE,
Expand Down Expand Up @@ -96,7 +95,8 @@ StatReferent <- ggproto(
params
},

compute_group = function(data, scales, subset = NULL, referent = NULL) data
compute_group = function(data, scales,
referent = NULL) data
)

# QUESTION: Why are the arguments apparently out of order?
Expand Down
130 changes: 130 additions & 0 deletions R/zzz-biplot-geoms.r
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#' @inheritParams ggplot2::geom_point
#' @inheritParams ggplot2::geom_path
#' @inheritParams ggplot2::geom_polygon
#' @inheritParams ggplot2::geom_density_2d
#' @inheritParams ggplot2::geom_density_2d_filled
#' @inheritParams ggplot2::geom_text
#' @inheritParams ggplot2::geom_label
#' @inheritParams ggrepel::geom_text_repel
Expand Down Expand Up @@ -229,6 +231,134 @@ geom_cols_polygon <- function(
)
}

#' @rdname biplot-geoms
#' @export
geom_rows_density_2d <- function(
mapping = NULL,
data = NULL,
stat = "density_2d",
position = "identity",
...,
contour_var = "density",
lineend = "butt",
linejoin = "round",
linemitre = 10,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
) {
layer(
mapping = mapping,
data = data,
stat = rows_stat(stat),
geom = GeomDensity2d,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
contour_var = contour_var,
lineend = lineend,
linejoin = linejoin,
linemitre = linemitre,
na.rm = na.rm,
...
)
)
}

#' @rdname biplot-geoms
#' @export
geom_cols_density_2d <- function(
mapping = NULL,
data = NULL,
stat = "density_2d",
position = "identity",
...,
contour_var = "density",
lineend = "butt",
linejoin = "round",
linemitre = 10,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
) {
layer(
mapping = mapping,
data = data,
stat = cols_stat(stat),
geom = GeomDensity2d,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
contour_var = contour_var,
lineend = lineend,
linejoin = linejoin,
linemitre = linemitre,
na.rm = na.rm,
...
)
)
}

#' @rdname biplot-geoms
#' @export
geom_rows_density_2d_filled <- function(
mapping = NULL,
data = NULL,
stat = "density_2d_filled",
position = "identity",
...,
contour_var = "density",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
) {
layer(
mapping = mapping,
data = data,
stat = rows_stat(stat),
geom = GeomDensity2dFilled,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
contour_var = contour_var,
na.rm = na.rm,
...
)
)
}

#' @rdname biplot-geoms
#' @export
geom_cols_density_2d_filled <- function(
mapping = NULL,
data = NULL,
stat = "density_2d_filled",
position = "identity",
...,
contour_var = "density",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
) {
layer(
mapping = mapping,
data = data,
stat = cols_stat(stat),
geom = GeomDensity2dFilled,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
contour_var = contour_var,
na.rm = na.rm,
...
)
)
}

#' @rdname biplot-geoms
#' @export
geom_rows_text <- function(
Expand Down
Loading

0 comments on commit 0a52715

Please sign in to comment.