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

added the option for geom_points #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
284 changes: 164 additions & 120 deletions R/plot-anomaly_diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
) {


Expand Down Expand Up @@ -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,
Expand Down