Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addition/interpolation, projection/prediction, and limiting/offsetting rule layers #64

Merged
merged 53 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
867aec3
feat(addition): draft new geom
corybrunson Sep 4, 2021
5fe9e7c
Merge branch 'main' into vecsum
corybrunson Sep 4, 2021
d2c4f04
feat(addition): full draft with sandbox example
corybrunson Sep 6, 2021
5f9ce2e
feat(addition): add chull and centroid grobs
corybrunson Sep 6, 2021
13d78e0
Merge branch 'main' into vecsum
corybrunson Sep 12, 2021
923b792
Merge branch 'main' into vecsum
corybrunson Jun 24, 2022
a6d89ed
Merge branch 'main' into vecsum-main
corybrunson Jul 2, 2022
880bcfc
quarantine addition geom from build + rebuild layers
corybrunson Jul 2, 2022
8cbdac6
use new interpolate aesthetic to make addition geom work for pca
corybrunson Jul 3, 2022
1145fff
Merge branch 'main' into vecsum
corybrunson Jul 13, 2022
3007d57
write idealized example with notes for changes to axis geom
corybrunson Sep 3, 2024
628cab2
Merge branch 'main' into calibrate
corybrunson Nov 20, 2024
e7192b1
enable numeric offset axes without adjusting window
corybrunson Nov 26, 2024
a658896
prototype align box stat to couple with axis geom
corybrunson Nov 27, 2024
79d159b
Merge branch 'calibrate' into offset
corybrunson Nov 27, 2024
f644a61
track rule sandbox + draft rule geom + refactor wrt axis geom
corybrunson Nov 27, 2024
e3f6085
draft toy custom geom layer
corybrunson Dec 2, 2024
abb014b
reorganize calibrated & offset axis into rule stat & axis geom
corybrunson Dec 2, 2024
13cad83
debug axis,rule,isoline geoms + extend angle,radius aesthetics to vec…
corybrunson Dec 3, 2024
bcb1eb4
rm ordination methods from vector example + ensure coordinates in dra…
corybrunson Dec 4, 2024
5ad01a7
rm ordr dependency from eigen & isoline examples
corybrunson Dec 4, 2024
c051bb5
rm ordr dependency of axis geom example + move rows/cols rule stat to…
corybrunson Dec 4, 2024
3012788
add sections on computed variables
corybrunson Dec 5, 2024
46a7870
address checks
corybrunson Dec 5, 2024
194999d
re-build row and column plot layers
corybrunson Dec 5, 2024
24f94c6
increment version + describe rule stat in news
corybrunson Dec 5, 2024
6a41b0f
draft tests for axis geom & rule stat
corybrunson Dec 6, 2024
1151cc9
write limits & offset function maker + complete rule stat tests
corybrunson Dec 6, 2024
b56562d
document rule stat + incorporate into readme (with buggy overlapping …
corybrunson Dec 7, 2024
a39132d
exclude offset positions from consideration for axis labels
corybrunson Dec 7, 2024
e8d3e17
credit ggplot2 extenders for feedback
corybrunson Dec 7, 2024
eb5ad49
rm commented axis geom
corybrunson Dec 7, 2024
aaa7e56
extend border intersection functions to offset axes
corybrunson Dec 8, 2024
3e7ce47
attempt to split axis geom into axis & rule + realize referent bug
corybrunson Dec 9, 2024
3932fa9
illustrate referent hassle in examples
corybrunson Dec 9, 2024
205b12a
rm redundances
corybrunson Dec 9, 2024
ca32e3a
refactor axis & rule geoms to avoid aesthetic names for internal vari…
corybrunson Dec 9, 2024
c610bd3
draft template referent stat
corybrunson Dec 21, 2024
cc0c0e5
draft projection stat with referent stat as parent
corybrunson Dec 21, 2024
6af4a2d
convert rule stat to referent stat child + resolve checks
corybrunson Dec 22, 2024
cfde8f0
update news per referential stats & projection stat
corybrunson Dec 22, 2024
e674c77
Merge branch 'vecsum' into offset-vecsum
corybrunson Dec 23, 2024
e56f3fd
enable referent stat to handle polar coordinates
corybrunson Dec 23, 2024
058938d
don't accept unnamed new_data + de-duplicate function only
corybrunson Dec 23, 2024
4125a34
rm support for polar coordinates; use only to evade window resizing
corybrunson Dec 23, 2024
5e0f062
position new ggprotos in website index
corybrunson Dec 23, 2024
40fffc6
shunt addition biplot layers to code generating script + document exa…
corybrunson Dec 23, 2024
ce10a7c
fix typo
corybrunson Dec 24, 2024
c92ea0d
rename addition geom to interpolation + change parent from vector to …
corybrunson Dec 24, 2024
bf2af42
extend projection stat to ordination aesthetics + update documentatio…
corybrunson Dec 25, 2024
e5d92a4
rename aspect_ratio to window_ratio
corybrunson Dec 25, 2024
ba46f41
Merge branch 'main' into offset
corybrunson Dec 25, 2024
8becf20
rebuild site
corybrunson Dec 25, 2024
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
7 changes: 6 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ordr
Title: A Tidyverse Extension for Ordinations and Biplots
Version: 0.1.1.0001
Version: 0.1.1.0002
Authors@R: c(
person("Jason Cory", "Brunson", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3126-9494")),
Expand Down Expand Up @@ -74,9 +74,11 @@ Collate:
'fun-lra.r'
'fun-wrap.r'
'geom-axis.r'
'geom-interpolation.r'
'geom-intervals.r'
'geom-isoline.r'
'geom-origin.r'
'geom-rule.r'
'geom-text-radiate.r'
'geom-utils.r'
'geom-vector.r'
Expand Down Expand Up @@ -105,6 +107,9 @@ Collate:
'stat-chull.r'
'stat-cone.r'
'stat-matrix.r'
'stat-referent.r'
'stat-projection.r'
'stat-rule.r'
'stat-scale.r'
'stat-spantree.r'
'themes.r'
Expand Down
26 changes: 26 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ S3method(biplot,tbl_ord)
S3method(dim,tbl_ord)
S3method(format,tbl_ord)
S3method(fortify,tbl_ord)
S3method(ggplot_add,LayerRef)
S3method(glance,tbl_ord)
S3method(lda_ord,data.frame)
S3method(lda_ord,default)
Expand Down Expand Up @@ -185,10 +186,12 @@ export("%>%")
export(CoordBiplot)
export(CoordRect)
export(GeomAxis)
export(GeomInterpolation)
export(GeomIsoline)
export(GeomLineranges)
export(GeomOrigin)
export(GeomPointranges)
export(GeomRule)
export(GeomTextRadiate)
export(GeomUnitCircle)
export(GeomVector)
Expand All @@ -199,18 +202,25 @@ export(StatColsCenter)
export(StatColsChull)
export(StatColsCone)
export(StatColsEllipse)
export(StatColsProjection)
export(StatColsRule)
export(StatColsScale)
export(StatColsSpantree)
export(StatColsStar)
export(StatCone)
export(StatProjection)
export(StatReferent)
export(StatRows)
export(StatRowsCenter)
export(StatRowsChull)
export(StatRowsCone)
export(StatRowsEllipse)
export(StatRowsProjection)
export(StatRowsRule)
export(StatRowsScale)
export(StatRowsSpantree)
export(StatRowsStar)
export(StatRule)
export(StatScale)
export(StatSpantree)
export(StatStar)
Expand All @@ -230,6 +240,7 @@ export(draw_key_line)
export(eigen_ord)
export(geom_axis)
export(geom_cols_axis)
export(geom_cols_interpolation)
export(geom_cols_isoline)
export(geom_cols_label)
export(geom_cols_label_repel)
Expand All @@ -238,16 +249,19 @@ export(geom_cols_path)
export(geom_cols_point)
export(geom_cols_pointranges)
export(geom_cols_polygon)
export(geom_cols_rule)
export(geom_cols_text)
export(geom_cols_text_radiate)
export(geom_cols_text_repel)
export(geom_cols_vector)
export(geom_interpolation)
export(geom_isoline)
export(geom_label_repel)
export(geom_lineranges)
export(geom_origin)
export(geom_pointranges)
export(geom_rows_axis)
export(geom_rows_interpolation)
export(geom_rows_isoline)
export(geom_rows_label)
export(geom_rows_label_repel)
Expand All @@ -256,10 +270,12 @@ export(geom_rows_path)
export(geom_rows_point)
export(geom_rows_pointranges)
export(geom_rows_polygon)
export(geom_rows_rule)
export(geom_rows_text)
export(geom_rows_text_radiate)
export(geom_rows_text_repel)
export(geom_rows_vector)
export(geom_rule)
export(geom_text_radiate)
export(geom_text_repel)
export(geom_unit_circle)
Expand All @@ -279,6 +295,9 @@ export(left_join_cols)
export(left_join_rows)
export(lra)
export(make_tbl_ord)
export(maxpp)
export(minabspp)
export(minpp)
export(mutate_cols)
export(mutate_rows)
export(negate_ord)
Expand Down Expand Up @@ -310,18 +329,25 @@ export(stat_cols_center)
export(stat_cols_chull)
export(stat_cols_cone)
export(stat_cols_ellipse)
export(stat_cols_projection)
export(stat_cols_rule)
export(stat_cols_scale)
export(stat_cols_spantree)
export(stat_cols_star)
export(stat_cone)
export(stat_projection)
export(stat_referent)
export(stat_rows)
export(stat_rows_center)
export(stat_rows_chull)
export(stat_rows_cone)
export(stat_rows_ellipse)
export(stat_rows_projection)
export(stat_rows_rule)
export(stat_rows_scale)
export(stat_rows_spantree)
export(stat_rows_star)
export(stat_rule)
export(stat_scale)
export(stat_spantree)
export(stat_star)
Expand Down
18 changes: 17 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,23 @@ Multiple harmonizers are now available for scaling secondary axes. That recommen
## GDA-geared coordinate systems

Two new coordinate systems provide control over the aspect ratio of the plotting window without compromising that of the (artificial) coordinate axes:
`GeomRect` (alias `GeomSquare`) extends `GeomFixed` with an `aspect_ratio` parameter for the plotting window, while `GeomBiplot` removes the `ratio` parameter and forces the coordinate axes to have aspect ratio 1.
`GeomRect` (alias `GeomSquare`) extends `GeomFixed` with an `window_ratio` parameter for the plotting window, while `GeomBiplot` removes the `ratio` parameter and forces the coordinate axes to have aspect ratio 1.

## referential stats

A new statistical transformation serves to parent specific "referential stats", meaning those that depend on non-inherited (in this setting, positional) data to transform the inherited data. The reference data are passed to the new `referent` parameter. The new stat is coupled with an additional `LayerRef` class that enables `ggplot_add()` to pass the inherited positional aesthetics to `$setup_params()`. Biplot-specific `stat_*_*()` shortcuts accept additional argument types to `referent` that result in the opposite matrix factor being used as reference data.

## projection stat

The 'projection' referential stat prepares segment endpoints between `x,y` positions and their projections on axes defined by the reference data. It is a natural graphical element for predictive biplots of ordination models of continuous data.

## rule stat

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.

## angle,radius specifications

Several geometric object layers ('vector', 'isoline', and 'axis') now accept polar as well as cartesian coordinates. Whereas cartesian coordinates influence the plotting window, polar coordinates do not, so this allows for the plot to ignore elements like axes that may not be intended to influence the window dimensions. This is an experimental convenience feature that may be removed in a future version.

# ordr 0.1.1

Expand Down
36 changes: 18 additions & 18 deletions R/coord-rect.r
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ CoordRect <- ggproto(
)
aesthetic_y <- scale_y$aesthetics[1]

# synchronize limits and ranges according to `aspect_ratio` after adjusting
# synchronize limits and ranges according to `window_ratio` after adjusting
# for `ratio` (if it is provided; it isn't in `CoordBiplot`)
adj_ratio <- self$aspect_ratio / (self$ratio %||% 1)
adj_ratio <- self$window_ratio / (self$ratio %||% 1)
limits <- reconcile_rectangle(limits_x, limits_y, adj_ratio)
continuous_range <- reconcile_rectangle(
continuous_range_x, continuous_range_y, adj_ratio
Expand Down Expand Up @@ -66,25 +66,25 @@ CoordBiplot <- ggproto(
}
)

#' Cartesian coordinates and plotting window with fixed aspect ratios
#' @title Cartesian coordinates and plotting window with fixed aspect ratios
#'
#' 2- (and 3-) dimensional biplots require that coordinates lie on the same
#' scale but may additionally benefit from a square plotting window. The
#' general-purpose coordinate system `CoordRect`, alias `CoordSquare`, provides
#' control of both coordinate and window aspect ratios, while the convenience
#' `CoordBiplot` system fixes the coordinate aspect ratio at `1` and gives the
#' user control only of the plotting window.
#' @description 2- (and 3-) dimensional biplots require that coordinates lie on
#' the same scale but may additionally benefit from a square plotting window.
#' The general-purpose coordinate system `CoordRect`, alias `CoordSquare`,
#' provides control of both coordinate and window aspect ratios, while the
#' convenience `CoordBiplot` system fixes the coordinate aspect ratio at `1`
#' and gives the user control only of the plotting window.
#'
#' @inheritParams ggplot2::coord_fixed
#' @param aspect_ratio aspect ratio of plotting window
#' @param window_ratio aspect ratio of plotting window
#' @examples
#' # ensures that the resolutions of the axes and the dimensions of the plotting
#' # window respect the specified aspect ratios
#'
#' p <- ggplot(mtcars, aes(mpg, hp/10)) + geom_point()
#' p + coord_rect(ratio = 1)
#' p + coord_rect(ratio = 1, aspect_ratio = 2)
#' p + coord_rect(ratio = 1, aspect_ratio = 1/2)
#' p + coord_rect(ratio = 1, window_ratio = 2)
#' p + coord_rect(ratio = 1, window_ratio = 1/2)
#' p + coord_rect(ratio = 5)
#' p + coord_rect(ratio = 1/5)
#' p + coord_rect(xlim = c(15, 30))
Expand All @@ -93,15 +93,15 @@ CoordBiplot <- ggproto(
#' # Resize the plot to see that the specified aspect ratio is maintained
#' @export
coord_rect <- function(
ratio = 1, aspect_ratio = ratio,
ratio = 1, window_ratio = ratio,
xlim = NULL, ylim = NULL, expand = TRUE, clip = "on"
) {
ggplot2:::check_coord_limits(xlim)
ggplot2:::check_coord_limits(ylim)
ggproto(
NULL, CoordRect,
limits = list(x = xlim, y = ylim),
ratio = ratio, aspect_ratio = aspect_ratio,
ratio = ratio, window_ratio = window_ratio,
expand = expand,
clip = clip
)
Expand All @@ -116,7 +116,7 @@ coord_square <- coord_rect
#' @examples
#' p <- ggplot(mtcars, aes(mpg, hp/10)) + geom_point()
#' p + coord_biplot()
#' p + coord_biplot(aspect_ratio = 2)
#' p + coord_biplot(window_ratio = 2)
#'
#' # prevent rescaling in response to `theme()` aspect ratio
#' p <- ggplot(mtcars, aes(mpg, hp/5)) + geom_point()
Expand All @@ -125,18 +125,18 @@ coord_square <- coord_rect
#'
#' # NB: `theme(aspect.ratio = )` overrides `Coord*$aspect`:
#' p + coord_fixed(ratio = 1) + theme(aspect.ratio = 1)
#' p + coord_biplot(aspect_ratio = 2) + theme(aspect.ratio = 1)
#' p + coord_biplot(window_ratio = 2) + theme(aspect.ratio = 1)
#' @export
coord_biplot <- function(
aspect_ratio = 1,
window_ratio = 1,
xlim = NULL, ylim = NULL, expand = TRUE, clip = "on"
) {
ggplot2:::check_coord_limits(xlim)
ggplot2:::check_coord_limits(ylim)
ggproto(
NULL, CoordBiplot,
limits = list(x = xlim, y = ylim),
aspect_ratio = aspect_ratio,
window_ratio = window_ratio,
expand = expand,
clip = clip
)
Expand Down
Loading