Skip to content

Commit d0f80e1

Browse files
committed
#118 Expose facet_trelliscope() parameters
1 parent 4cc3348 commit d0f80e1

File tree

7 files changed

+138
-29
lines changed

7 files changed

+138
-29
lines changed

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# timetk 2.8.0.9000 (Development Version)
22

3+
### Trelliscope Plotting
4+
5+
- Expose the `facet_trelliscope()` plotting parameters.
6+
- `plot_time_series()`
7+
- `plot_time_series_boxplot()`
8+
- `plot_anomaly_diagnostics()`
9+
310
# timetk 2.8.0
411

512
__New Features__

R/plot-anomaly_diagnostics.R

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
#' If FALSE, returns a static `ggplot2` plot.
3636
#' @param .trelliscope Returns either a normal plot or a trelliscopejs plot (great for many time series)
3737
#' Must have `trelliscopejs` installed.
38+
#' @param .trelliscope_params Pass parameters to the `trelliscopejs::facet_trelliscope()` function as a `list()`.
39+
#' The only parameters that cannot be passed are:
40+
#' - `ncol`: use `.facet_ncol`
41+
#' - `nrow`: use `.facet_nrow`
42+
#' - `scales`: use `facet_scales`
43+
#' - `as_plotly`: use `.interactive`
3844
#'
3945
#'
4046
#' @return A `plotly` or `ggplot2` visualization
@@ -151,7 +157,8 @@ plot_anomaly_diagnostics <- function(
151157
.color_lab = "Anomaly",
152158

153159
.interactive = TRUE,
154-
.trelliscope = FALSE
160+
.trelliscope = FALSE,
161+
.trelliscope_params = list()
155162
) {
156163

157164
# Checks
@@ -212,7 +219,8 @@ plot_anomaly_diagnostics.data.frame <- function(
212219
.color_lab = "Anomaly",
213220

214221
.interactive = TRUE,
215-
.trelliscope = FALSE
222+
.trelliscope = FALSE,
223+
.trelliscope_params = list()
216224
) {
217225

218226
# Tidy Eval Setup
@@ -331,14 +339,27 @@ plot_anomaly_diagnostics.data.frame <- function(
331339

332340
} else {
333341

334-
g <- g +
335-
trelliscopejs::facet_trelliscope(
336-
facets = ggplot2::vars(!!! rlang::syms(facet_names)),
342+
# g <- g +
343+
# trelliscopejs::facet_trelliscope(
344+
# facets = ggplot2::vars(!!! rlang::syms(facet_names)),
345+
# ncol = .facet_ncol,
346+
# nrow = .facet_nrow,
347+
# scales = .facet_scales,
348+
# as_plotly = .interactive
349+
# )
350+
351+
trell <- do.call(trelliscopejs::facet_trelliscope, c(
352+
list(
353+
facets = ggplot2::vars(!!! rlang::syms(group_names)),
337354
ncol = .facet_ncol,
338355
nrow = .facet_nrow,
339356
scales = .facet_scales,
340357
as_plotly = .interactive
341-
)
358+
),
359+
.trelliscope_params
360+
))
361+
362+
g <- g + trell
342363

343364
}
344365

@@ -385,7 +406,8 @@ plot_anomaly_diagnostics.grouped_df <- function(
385406
.color_lab = "Anomaly",
386407

387408
.interactive = TRUE,
388-
.trelliscope = FALSE
409+
.trelliscope = FALSE,
410+
.trelliscope_params = list()
389411
) {
390412

391413

@@ -445,7 +467,8 @@ plot_anomaly_diagnostics.grouped_df <- function(
445467
.color_lab = .color_lab,
446468

447469
.interactive = .interactive,
448-
.trelliscope = .trelliscope
470+
.trelliscope = .trelliscope,
471+
.trelliscope_params = .trelliscope_params
449472
)
450473

451474
}

R/plot-time_series.R

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@
4747
#' @param .y_lab Y-axis label for the plot
4848
#' @param .color_lab Legend label if a `color_var` is used.
4949
#' @param .interactive Returns either a static (`ggplot2`) visualization or an interactive (`plotly`) visualization
50-
#' @param .plotly_slider If TRUE, returns a plotly date range slider.
50+
#' @param .plotly_slider If `TRUE`, returns a plotly date range slider.
5151
#' @param .trelliscope Returns either a normal plot or a trelliscopejs plot (great for many time series)
5252
#' Must have `trelliscopejs` installed.
53+
#' @param .trelliscope_params Pass parameters to the `trelliscopejs::facet_trelliscope()` function as a `list()`.
54+
#' The only parameters that cannot be passed are:
55+
#' - `ncol`: use `.facet_ncol`
56+
#' - `nrow`: use `.facet_nrow`
57+
#' - `scales`: use `facet_scales`
58+
#' - `as_plotly`: use `.interactive`
5359
#'
5460
#' @return A static `ggplot2` plot or an interactive `plotly` plot
5561
#'
@@ -182,7 +188,8 @@ plot_time_series <- function(
182188

183189
.interactive = TRUE,
184190
.plotly_slider = FALSE,
185-
.trelliscope = FALSE
191+
.trelliscope = FALSE,
192+
.trelliscope_params = list()
186193
) {
187194

188195
# Tidyeval Setup
@@ -245,7 +252,9 @@ plot_time_series.data.frame <- function(
245252

246253
.interactive = TRUE,
247254
.plotly_slider = FALSE,
248-
.trelliscope = FALSE
255+
256+
.trelliscope = FALSE,
257+
.trelliscope_params = list()
249258
) {
250259

251260

@@ -442,14 +451,27 @@ plot_time_series.data.frame <- function(
442451

443452
} else {
444453

445-
g <- g +
446-
trelliscopejs::facet_trelliscope(
447-
facets = ggplot2::vars(!!! rlang::syms(facet_names)),
454+
# g <- g +
455+
# trelliscopejs::facet_trelliscope(
456+
# facets = ggplot2::vars(!!! rlang::syms(facet_names)),
457+
# ncol = .facet_ncol,
458+
# nrow = .facet_nrow,
459+
# scales = .facet_scales,
460+
# as_plotly = .interactive
461+
# )
462+
463+
trell <- do.call(trelliscopejs::facet_trelliscope, c(
464+
list(
465+
facets = ggplot2::vars(!!! rlang::syms(group_names)),
448466
ncol = .facet_ncol,
449467
nrow = .facet_nrow,
450468
scales = .facet_scales,
451469
as_plotly = .interactive
452-
)
470+
),
471+
.trelliscope_params
472+
))
473+
474+
g <- g + trell
453475

454476
}
455477

@@ -497,7 +519,8 @@ plot_time_series.grouped_df <- function(
497519

498520
.interactive = TRUE,
499521
.plotly_slider = FALSE,
500-
.trelliscope = FALSE
522+
.trelliscope = FALSE,
523+
.trelliscope_params = list()
501524
) {
502525

503526
# Tidy Eval Setup
@@ -555,9 +578,12 @@ plot_time_series.grouped_df <- function(
555578
.title = .title,
556579
.x_lab = .x_lab,
557580
.y_lab = .y_lab,
581+
558582
.interactive = .interactive,
583+
.plotly_slider = .plotly_slider,
584+
559585
.trelliscope = .trelliscope,
560-
.plotly_slider = .plotly_slider
586+
.trelliscope_params = .trelliscope_params
561587
)
562588

563589

R/plot-time_series_boxplot.R

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
#' @param .plotly_slider If TRUE, returns a plotly date range slider.
6262
#' @param .trelliscope Returns either a normal plot or a trelliscopejs plot (great for many time series)
6363
#' Must have `trelliscopejs` installed.
64+
#' @param .trelliscope_params Pass parameters to the `trelliscopejs::facet_trelliscope()` function as a `list()`.
65+
#' The only parameters that cannot be passed are:
66+
#' - `ncol`: use `.facet_ncol`
67+
#' - `nrow`: use `.facet_nrow`
68+
#' - `scales`: use `facet_scales`
69+
#' - `as_plotly`: use `.interactive`
6470
#'
6571
#' @return A static `ggplot2` plot or an interactive `plotly` plot
6672
#'
@@ -215,7 +221,8 @@ plot_time_series_boxplot <- function(
215221

216222
.interactive = TRUE,
217223
.plotly_slider = FALSE,
218-
.trelliscope = FALSE
224+
.trelliscope = FALSE,
225+
.trelliscope_params = list()
219226
) {
220227

221228
# Tidyeval Setup
@@ -281,7 +288,8 @@ plot_time_series_boxplot.data.frame <- function(
281288

282289
.interactive = TRUE,
283290
.plotly_slider = FALSE,
284-
.trelliscope = FALSE
291+
.trelliscope = FALSE,
292+
.trelliscope_params = list()
285293
) {
286294

287295

@@ -500,14 +508,27 @@ plot_time_series_boxplot.data.frame <- function(
500508

501509
} else {
502510

503-
g <- g +
504-
trelliscopejs::facet_trelliscope(
505-
facets = ggplot2::vars(!!! rlang::syms(facet_names)),
511+
# g <- g +
512+
# trelliscopejs::facet_trelliscope(
513+
# facets = ggplot2::vars(!!! rlang::syms(facet_names)),
514+
# ncol = .facet_ncol,
515+
# nrow = .facet_nrow,
516+
# scales = .facet_scales,
517+
# as_plotly = .interactive
518+
# )
519+
520+
trell <- do.call(trelliscopejs::facet_trelliscope, c(
521+
list(
522+
facets = ggplot2::vars(!!! rlang::syms(group_names)),
506523
ncol = .facet_ncol,
507524
nrow = .facet_nrow,
508525
scales = .facet_scales,
509526
as_plotly = .interactive
510-
)
527+
),
528+
.trelliscope_params
529+
))
530+
531+
g <- g + trell
511532

512533
}
513534

@@ -553,7 +574,8 @@ plot_time_series_boxplot.grouped_df <- function(
553574

554575
.interactive = TRUE,
555576
.plotly_slider = FALSE,
556-
.trelliscope = FALSE
577+
.trelliscope = FALSE,
578+
.trelliscope_params = list()
557579
) {
558580

559581
# Tidy Eval Setup
@@ -616,7 +638,8 @@ plot_time_series_boxplot.grouped_df <- function(
616638
.y_lab = .y_lab,
617639
.interactive = .interactive,
618640
.plotly_slider = .plotly_slider,
619-
.trelliscope = .trelliscope
641+
.trelliscope = .trelliscope,
642+
.trelliscope_params = .trelliscope_params
620643
)
621644

622645

man/plot_anomaly_diagnostics.Rd

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot_time_series.Rd

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot_time_series_boxplot.Rd

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)