Comments (1)
library(timetk)
library(dplyr)
ts_sma_plot <- function(.data, .sma_order, .func = mean, .align = "center",
.partial = FALSE, .multi_plot = FALSE,
.interactive = FALSE) {
# * Tidyeval ----
# slidify_vec parameters
sma_vec <- as.vector(.sma_order)
sma_fun <- .func
sma_align <- stringr::str_to_lower(as.character(.align))
sma_partial <- as.logical(.partial)
multi_plot <- as.logical(.multi_plot)
interactive <- as.logical(.interactive)
# * Checks ----
if(!sma_align %in% c("center","left","right")){
stop(call. = FALSE, "(.align) must be either 'center','left', or 'right'")
}
if(!is.numeric(sma_vec)){
stop(call. = FALSE, "(.sma_order) must be all numeric values, c(1,2,3,...)")
}
if(!is.logical(sma_partial) & !is.logical(multi_plot) & !is.logical(interactive)){
stop(call. = FLASE, "(.partial) (.multi_plot) and (.interactive) must all be logical values.")
}
# Get data object
ts_obj <- .data
# Get data and try to coerce to tibble
# We do this because we use timetk::slidify_vec
if(stats::is.ts(ts_obj) | stats::is.mts(ts_obj) | xts::is.xts(ts_obj) | zoo::is.zoo(ts_obj)){
message("Attempting to coerce to a tibble.")
ts_tbl <- timetk::tk_tbl(ts_obj) # change to internal ts_to_tbl() func
} else {
ts_tbl <- ts_obj
}
# * Loop through periods ----
df <- data.frame(matrix(ncol = 0, nrow = 0))
for(i in sma_vec){
ret_tmp <- ts_tbl %>%
dplyr::mutate(sma_order = i) %>%
dplyr::mutate(sma_value = timetk::slidify_vec(
.x = value,
.f = sma_fun,
.period = i,
.align = sma_align,
.partial = sma_partial
))
df <- base::rbind(df, ret_tmp)
}
# * Plots ----
# * Return ----
return(df)
}
from healthyr.ts.
Related Issues (20)
- Function `ts_event_analysis_plot()`
- Add `ci_hi()` and `ci_lo()` functions
- Minor Data utilities
- Add `kernlab` to the `ts_model_tune_spec_template`
- Release healthyR.ts 0.2.1
- Make helper function to pull wflw_fit from boilerplate functions
- Add attributes to boilerplate functions
- `ts_sma_plot()` breaks if there is not a column called value HOT 1
- Fix `ts_ma_plot()` value col name in slidify HOT 1
- `ts_auto_lm()` Fails all models
- Fix select satement in ts_lag_correlation() function
- Release healthyR.ts 0.2.2
- Create `ts_wfs_xgoost()`
- Update `ts_calendar_heatmap_plot()`
- Release healthyR.ts 0.2.3
- Failure with `ts_model_auto_tune()` due to `ts_model_spec_tune_template()`
- Release healthyR.ts 0.2.4
- Linear non linear regression to lag plots
- `ts_lag_correlations()` fails on non numeric .x columns HOT 1
- Release healthyR.ts 0.2.5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from healthyr.ts.