Skip to content

Commit

Permalink
Add fn_align_plot
Browse files Browse the repository at this point in the history
  • Loading branch information
YuhangTom committed Mar 18, 2024
1 parent 617f597 commit 806bb76
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
24 changes: 23 additions & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ references:
title: spelling
abstract: 'spelling: Tools for Spell Checking in R'
notes: Suggests
url: https://docs.ropensci.org/spelling/
url: https://ropensci.r-universe.dev/spelling
repository: https://CRAN.R-project.org/package=spelling
authors:
- family-names: Ooms
Expand Down Expand Up @@ -251,6 +251,9 @@ references:
- family-names: Dunnington
given-names: Dewey
orcid: https://orcid.org/0000-0002-9415-4582
- family-names: van den Brand
given-names: Teun
orcid: https://orcid.org/0000-0002-9335-7468
year: '2024'
- type: software
title: imager
Expand Down Expand Up @@ -445,6 +448,25 @@ references:
email: [email protected]
orcid: https://orcid.org/0000-0002-6983-2759
year: '2024'
- type: software
title: zoo
abstract: 'zoo: S3 Infrastructure for Regular and Irregular Time Series (Z''s Ordered
Observations)'
notes: Imports
url: https://zoo.R-Forge.R-project.org/
repository: https://CRAN.R-project.org/package=zoo
authors:
- family-names: Zeileis
given-names: Achim
email: [email protected]
orcid: https://orcid.org/0000-0003-0918-3766
- family-names: Grothendieck
given-names: Gabor
email: [email protected]
- family-names: Ryan
given-names: Jeffrey A.
email: [email protected]
year: '2024'
- type: software
title: 'R: A Language and Environment for Statistical Computing'
notes: Depends
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Imports:
png,
grDevices,
graphics,
readr
readr,
zoo
Remotes:
heike/bulletxtrctr
Depends:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ importFrom(stringr,str_detect)
importFrom(tidyr,nest)
importFrom(tidyr,pivot_longer)
importFrom(tidyr,unnest)
importFrom(zoo,na.trim)
13 changes: 13 additions & 0 deletions R/x3p_shift.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#' @importFrom purrr map_dbl map set_names
#' @importFrom tidyr nest unnest
#' @importFrom assertthat assert_that is.flag
#' @importFrom zoo na.trim
#' @export
#' @examples
#' x3p <- x3p_subsamples[[2]]
Expand All @@ -30,6 +31,7 @@
#'
#' attr(x3p_approx, "x3p_before_shift_plot")
#' attr(x3p_approx, "x3p_after_shift_plot")
#' attr(x3p_approx, "fn_align_plot")
#' attr(x3p_approx, "MSE_plot")
#' }
#'
Expand All @@ -49,6 +51,7 @@ x3p_shift <- function(x3p, ifplot = FALSE, delta = -5:5,
x_shift_delta <-
Dat <-
value_approx <-
f <-
NULL

ggplot_attrs <- NA
Expand Down Expand Up @@ -246,6 +249,16 @@ x3p_shift <- function(x3p, ifplot = FALSE, delta = -5:5,
f1 <- x3p$surface.matrix[, yidx_mid]
f2 <- x3p$surface.matrix[, yidx[j]]

attr(ggplot_attrs, "fn_align_plot") <- tibble(f1, f2) %>%
na.trim() %>%
mutate(x = 1:n()) %>%
pivot_longer(f1:f2, names_to = "f", names_prefix = "f") %>%
mutate(f = ifelse(f == "1", paste0(yidx_mid, " (ref)"), yidx[j])) %>%
ggplot(aes(x = x, y = value, color = f)) +
geom_line() +
scale_colour_brewer(palette = "Paired") +
theme_bw()

### Mean squared error for all delta
MSE <- map_dbl(delta, function(delta_i) {
### Too few non-missing values, cannot do anything
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![Last-changedate](https://img.shields.io/badge/last%20change-2024--03--02-yellowgreen.svg)](https://github.com/YuhangTom/wire/commits/main)
[![Last-changedate](https://img.shields.io/badge/last%20change-2024--03--18-yellowgreen.svg)](https://github.com/YuhangTom/wire/commits/main)
[![CRAN
status](https://www.r-pkg.org/badges/version/wire.png)](https://CRAN.R-project.org/package=wire)
[![Codecov test
Expand Down Expand Up @@ -168,6 +168,8 @@ attr(raw_sig_df, "sig_df_plot")
``` r

shift_sig_df <- x3p_shift_sig_df(x3p_bin_rotate, ifplot = TRUE)
#> Error : Chromote: timed out waiting for event Page.loadEventFired
#> Error : Chromote: timed out waiting for event Page.loadEventFired
attr(shift_sig_df, "x3p_before_shift_plot")
```

Expand Down
1 change: 1 addition & 0 deletions man/x3p_shift.Rd

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

3 changes: 3 additions & 0 deletions tests/testthat/test-x3p_shift.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ test_that("output plot works", {
expect_visible(
attr(x3p_approx, "MSE_plot")
)
expect_visible(
attr(x3p_approx, "fn_align_plot")
)
})


Expand Down

0 comments on commit 806bb76

Please sign in to comment.