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

Conversation

corybrunson
Copy link
Owner

This PR addresses half of #4, which should remain open. It is feature-complete and (i believe) only unit tests remain to be written.

corybrunson and others added 30 commits September 4, 2021 13:14
@corybrunson
Copy link
Owner Author

All tests pass and examples work as expected.

However, GeomAxis has become quite complicated, with an absurd number of conditionals based on whether the received data include limit and offset aesthetics. I believe it should be split into GeomAxis (for unlimited lines, with or without offsets) and GeomRule (for limited segments, with or without offsets). Then StatRule will pair by default with GeomRule, which will expect axis,lower,upper and welcome (optionally) yintercept,xintercept. Meanwhile, StatRule can also pair with GeomAxis, which will welcome both pairs of aesthetics.

Importantly, the behavior of layer(stat = "rule", geom = "axis") should be different than current if lower,upper are provided: The axes should still be drawn as unlimited lines, but the lower and upper limits should be included in $setup_data() so that the plotting window includes them. If lower,upper are not provided, then the current behavior of widening the window only to include the offset vectors should remain.

@corybrunson
Copy link
Owner Author

I believe this is ready to merge. It resolves all of #4 (!), where much of the thinking is documented, as well as #58.

@corybrunson
Copy link
Owner Author

I almost forgot to make StatProjection compatible with ord_aes() i.e. to enable plotting projections (from full ordination space onto biplot space) of segments (projecting inherited data to reference data) as well as segments projecting projections (from full to biplot) of inherited data to projections of reference data. The iris data example will be revised to illustrate this functionality. Since old code will be deleted, the reprex below (with the revised code implemented as StatProjection2) shows that the refactoring is actually more time- and memory-efficient, likely due largely to more clever use of matrix operations.

library(devtools)
#> Loading required package: usethis
load_all("~/Documents/software/ordr/")
#> ℹ Loading ordr
#> Loading required package: ggplot2
iris_pca <- ordinate(iris, cols = 1:4, model = prcomp)
bench::mark(
  `1` = {
    p <- ggbiplot(iris_pca, aes(color = Species, label = name)) +
      stat_rows_projection()
    layer_data(p)
  },
  `2` = {
    p <- ggbiplot(iris_pca, aes(color = Species, label = name)) +
      stat_rows_projection2()
    layer_data(p)
  },
  check = FALSE
)
#> # A tibble: 2 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 1            32.7ms   33.3ms      29.7    9.61MB     7.42
#> 2 2            27.6ms   28.4ms      35.0    2.25MB    10.8
bench::mark(
  `1` = {
    p <- ggbiplot(iris_pca, ord_aes(iris_pca, color = Species, label = name)) +
      stat_rows_projection()
    layer_data(p)
  },
  `2` = {
    p <- ggbiplot(iris_pca, ord_aes(iris_pca, color = Species, label = name)) +
      stat_rows_projection2()
    layer_data(p)
  },
  check = FALSE
)
#> # A tibble: 2 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 1            33.6ms     35ms      28.1    1.64MB    12.5 
#> 2 2            29.3ms   29.9ms      33.0    1.25MB     7.07

Created on 2024-12-25 with reprex v2.1.1

@corybrunson corybrunson changed the title rule stat for limiting and offsetting axes addition/interpolation, projection/prediction, and limiting/offsetting rule layers Dec 25, 2024
@corybrunson corybrunson merged commit 64b426d into main Dec 25, 2024
@corybrunson corybrunson deleted the offset branch December 26, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant