diff --git a/R/plot-anomaly_diagnostics.R b/R/plot-anomaly_diagnostics.R index a99034c1..e2c6c202 100644 --- a/R/plot-anomaly_diagnostics.R +++ b/R/plot-anomaly_diagnostics.R @@ -119,46 +119,53 @@ #' @name plot_anomaly_diagnostics #' @export plot_anomaly_diagnostics <- function( - .data, .date_var, .value, - - .facet_vars = NULL, - - .frequency = "auto", - .trend = "auto", - .alpha = 0.05, - .max_anomalies = 0.2, - .message = TRUE, - - .facet_ncol = 1, - .facet_nrow = 1, - .facet_scales = "free", - .facet_dir = "h", - .facet_collapse = FALSE, - .facet_collapse_sep = " ", - .facet_strip_remove = FALSE, - - .line_color = "#2c3e50", - .line_size = 0.5, - .line_type = 1, - .line_alpha = 1, - - .anom_color = "#e31a1c", - .anom_alpha = 1, - .anom_size = 1.5, - - .ribbon_fill = "grey20", - .ribbon_alpha = 0.20, - - .legend_show = TRUE, - - .title = "Anomaly Diagnostics", - .x_lab = "", - .y_lab = "", - .color_lab = "Anomaly", - - .interactive = TRUE, - .trelliscope = FALSE, - .trelliscope_params = list() + .data, .date_var, .value, + + .facet_vars = NULL, + + .frequency = "auto", + .trend = "auto", + .alpha = 0.05, + .max_anomalies = 0.2, + .message = TRUE, + + .facet_ncol = 1, + .facet_nrow = 1, + .facet_scales = "free", + .facet_dir = "h", + .facet_collapse = FALSE, + .facet_collapse_sep = " ", + .facet_strip_remove = FALSE, + + .line_color = "#2c3e50", + .line_size = 0.5, + .line_type = 1, + .line_alpha = 1, + + .show_points = FALSE, + .point_shape = 16, + .point_size = 1, + .point_alpha = 1, + .point_color = "black", + .point_fill = NA, + + .anom_color = "#e31a1c", + .anom_alpha = 1, + .anom_size = 1.5, + + .ribbon_fill = "grey20", + .ribbon_alpha = 0.20, + + .legend_show = TRUE, + + .title = "Anomaly Diagnostics", + .x_lab = "", + .y_lab = "", + .color_lab = "Anomaly", + + .interactive = TRUE, + .trelliscope = FALSE, + .trelliscope_params = list() ) { # Checks @@ -181,46 +188,53 @@ plot_anomaly_diagnostics <- function( #' @export plot_anomaly_diagnostics.data.frame <- function( - .data, .date_var, .value, - - .facet_vars = NULL, - - .frequency = "auto", - .trend = "auto", - .alpha = 0.05, - .max_anomalies = 0.2, - .message = TRUE, - - .facet_ncol = 1, - .facet_nrow = 1, - .facet_scales = "free", - .facet_dir = "h", - .facet_collapse = FALSE, - .facet_collapse_sep = " ", - .facet_strip_remove = FALSE, - - .line_color = "#2c3e50", - .line_size = 0.5, - .line_type = 1, - .line_alpha = 1, - - .anom_color = "#e31a1c", - .anom_alpha = 1, - .anom_size = 1.5, - - .ribbon_fill = "grey20", - .ribbon_alpha = 0.20, - - .legend_show = TRUE, - - .title = "Anomaly Diagnostics", - .x_lab = "", - .y_lab = "", - .color_lab = "Anomaly", - - .interactive = TRUE, - .trelliscope = FALSE, - .trelliscope_params = list() + .data, .date_var, .value, + + .facet_vars = NULL, + + .frequency = "auto", + .trend = "auto", + .alpha = 0.05, + .max_anomalies = 0.2, + .message = TRUE, + + .facet_ncol = 1, + .facet_nrow = 1, + .facet_scales = "free", + .facet_dir = "h", + .facet_collapse = FALSE, + .facet_collapse_sep = " ", + .facet_strip_remove = FALSE, + + .line_color = "#2c3e50", + .line_size = 0.5, + .line_type = 1, + .line_alpha = 1, + + .show_points = FALSE, + .point_shape = 16, + .point_size = 1, + .point_alpha = 1, + .point_color = "black", + .point_fill = NA, + + .anom_color = "#e31a1c", + .anom_alpha = 1, + .anom_size = 1.5, + + .ribbon_fill = "grey20", + .ribbon_alpha = 0.20, + + .legend_show = TRUE, + + .title = "Anomaly Diagnostics", + .x_lab = "", + .y_lab = "", + .color_lab = "Anomaly", + + .interactive = TRUE, + .trelliscope = FALSE, + .trelliscope_params = list() ) { # Tidy Eval Setup @@ -307,6 +321,22 @@ plot_anomaly_diagnostics.data.frame <- function( alpha = .line_alpha ) + + # Add points + if (.show_points == TRUE) { + + g <- g + + ggplot2::geom_point( + shape = .point_shape, + size = .point_size, + alpha = .point_alpha, + color = .point_color, + fill = .point_fill + ) + + } + + # Add Outliers g <- g + ggplot2::geom_point(ggplot2::aes_string(color = "anomaly"), size = .anom_size, alpha = .anom_alpha, @@ -368,46 +398,53 @@ plot_anomaly_diagnostics.data.frame <- function( #' @export plot_anomaly_diagnostics.grouped_df <- function( - .data, .date_var, .value, - - .facet_vars = NULL, - - .frequency = "auto", - .trend = "auto", - .alpha = 0.05, - .max_anomalies = 0.2, - .message = TRUE, - - .facet_ncol = 1, - .facet_nrow = 1, - .facet_scales = "free", - .facet_dir = "h", - .facet_collapse = FALSE, - .facet_collapse_sep = " ", - .facet_strip_remove = FALSE, - - .line_color = "#2c3e50", - .line_size = 0.5, - .line_type = 1, - .line_alpha = 1, - - .anom_color = "#e31a1c", - .anom_alpha = 1, - .anom_size = 1.5, - - .ribbon_fill = "grey20", - .ribbon_alpha = 0.20, - - .legend_show = TRUE, - - .title = "Anomaly Diagnostics", - .x_lab = "", - .y_lab = "", - .color_lab = "Anomaly", - - .interactive = TRUE, - .trelliscope = FALSE, - .trelliscope_params = list() + .data, .date_var, .value, + + .facet_vars = NULL, + + .frequency = "auto", + .trend = "auto", + .alpha = 0.05, + .max_anomalies = 0.2, + .message = TRUE, + + .facet_ncol = 1, + .facet_nrow = 1, + .facet_scales = "free", + .facet_dir = "h", + .facet_collapse = FALSE, + .facet_collapse_sep = " ", + .facet_strip_remove = FALSE, + + .line_color = "#2c3e50", + .line_size = 0.5, + .line_type = 1, + .line_alpha = 1, + + .show_points = FALSE, + .point_shape = 16, + .point_size = 1, + .point_alpha = 1, + .point_color = "black", + .point_fill = NA, + + .anom_color = "#e31a1c", + .anom_alpha = 1, + .anom_size = 1.5, + + .ribbon_fill = "grey20", + .ribbon_alpha = 0.20, + + .legend_show = TRUE, + + .title = "Anomaly Diagnostics", + .x_lab = "", + .y_lab = "", + .color_lab = "Anomaly", + + .interactive = TRUE, + .trelliscope = FALSE, + .trelliscope_params = list() ) { @@ -452,6 +489,13 @@ plot_anomaly_diagnostics.grouped_df <- function( .line_type = .line_type, .line_alpha = .line_alpha, + .show_points = .show_points, + .point_shape = .point_shape, + .point_size = .point_size, + .point_alpha = .point_alpha, + .point_color = .point_color, + .point_fill = .point_fill, + .anom_color = .anom_color, .anom_alpha = .anom_alpha, .anom_size = .anom_size,