diff --git a/DESCRIPTION b/DESCRIPTION index 3cd891d..818e031 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,7 @@ Imports: rlang, tibble, tidyr (>= 1.0.0), - ggplot2 + ggplot2 (>= 3.4.0) RoxygenNote: 7.2.3 Roxygen: list(markdown = TRUE) Suggests: diff --git a/NAMESPACE b/NAMESPACE index 3ec3e2f..49e0ee0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -53,6 +53,7 @@ importFrom(ggplot2,"%+replace%") importFrom(rlang,"!!!") importFrom(rlang,"!!") importFrom(rlang,":=") +importFrom(rlang,.data) importFrom(stats,as.formula) importFrom(stats,mad) importFrom(stats,median) diff --git a/R/anomalize-package.R b/R/anomalize-package.R index 1667b7c..0dc38c6 100644 --- a/R/anomalize-package.R +++ b/R/anomalize-package.R @@ -1,5 +1,4 @@ -#' anomalize: Tidy anomaly detection -#' +#' @description #' The 'anomalize' package enables a "tidy" workflow for detecting anomalies in data. #' The main functions are time_decompose(), anomalize(), and time_recompose(). #' When combined, it's quite simple to decompose time series, detect anomalies, @@ -14,14 +13,14 @@ #' #' To learn more about `anomalize`, start with the vignettes: #' `browseVignettes(package = "anomalize")` -#' -#' -#' @docType package -#' @name anomalize_package -#' #' @aliases anomalize-package -#' @importFrom rlang := !! !!! +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +#' @importFrom rlang := !! !!! .data #' @importFrom dplyr %>% n row_number contains quo_name #' @importFrom stats median mad qt as.formula #' @import ggplot2 +## usethis namespace: end NULL diff --git a/R/plot_anomalies.R b/R/plot_anomalies.R index ab3b8a2..e9a4c2e 100644 --- a/R/plot_anomalies.R +++ b/R/plot_anomalies.R @@ -27,7 +27,6 @@ #' library(dplyr) #' library(ggplot2) #' -#' data(tidyverse_cran_downloads) #' #' #### SINGLE TIME SERIES #### #' tidyverse_cran_downloads %>% @@ -80,7 +79,7 @@ plot_anomalies.tbl_time <- function(data, time_recomposed = FALSE, ncol = 1, date_col <- tibbletime::get_index_char(data) g <- data %>% - ggplot2::ggplot(ggplot2::aes_string(x = date_col, y = "observed")) + ggplot2::ggplot(ggplot2::aes(x = .data[[date_col]], y = .data[["observed"]])) if (time_recomposed) { @@ -94,8 +93,8 @@ plot_anomalies.tbl_time <- function(data, time_recomposed = FALSE, ncol = 1, } g <- g + - ggplot2::geom_point(ggplot2::aes_string(color = "anomaly"), size = size_dots, alpha = alpha_dots) + - ggplot2::geom_point(ggplot2::aes_string(x = date_col, y = "observed", color = "anomaly"), + ggplot2::geom_point(ggplot2::aes(color = .data[["anomaly"]]), size = size_dots, alpha = alpha_dots) + + ggplot2::geom_point(ggplot2::aes(x = .data[[date_col]], y = .data[["observed"]], color = .data[["anomaly"]]), size = size_circles, shape = 1, alpha = alpha_circles, data = data %>% dplyr::filter(anomaly == "Yes"), inherit.aes = FALSE) + diff --git a/R/plot_anomaly_decomposition.R b/R/plot_anomaly_decomposition.R index 9f7cbbf..85e3357 100644 --- a/R/plot_anomaly_decomposition.R +++ b/R/plot_anomaly_decomposition.R @@ -27,8 +27,6 @@ #' library(dplyr) #' library(ggplot2) #' -#' data(tidyverse_cran_downloads) -#' #' tidyverse_cran_downloads %>% #' filter(package == "tidyquant") %>% #' ungroup() %>% @@ -78,11 +76,11 @@ plot_anomaly_decomposition.tbl_time <- function(data, ncol = 1, color_no = "#2c3 date_col <- tibbletime::get_index_char(data) data_anomaly_tbl <- data %>% - dplyr::select(!! date_expr, observed:remainder, anomaly) %>% + dplyr::select(!!date_expr, observed:remainder, anomaly) %>% tidyr::gather(key = key, value = value, -dplyr::one_of(c(!! date_col, 'anomaly')), factor_key = T) g <- data_anomaly_tbl %>% - ggplot2::ggplot(ggplot2::aes_string(x = date_col, y = "value", color = "anomaly")) + + ggplot2::ggplot(ggplot2::aes(x = .data[[date_col]], y = .data$value, color = .fata$anomaly)) + # Points ggplot2::geom_point(size = size_dots, alpha = alpha_dots) + # Circles diff --git a/R/tidyquant_theme_compat.R b/R/tidyquant_theme_compat.R index 2fb917f..a1973a6 100644 --- a/R/tidyquant_theme_compat.R +++ b/R/tidyquant_theme_compat.R @@ -15,10 +15,10 @@ theme_tq <- function(base_size = 11, base_family = "") { ggplot2::theme( # Base Inherited Elements - line = ggplot2::element_line(colour = blue, size = 0.5, linetype = 1, + line = ggplot2::element_line(colour = blue, linewidth = 0.5, linetype = 1, lineend = "butt"), rect = ggplot2::element_rect(fill = white, colour = blue, - size = 0.5, linetype = 1), + linewidth = 0.5, linetype = 1), text = ggplot2::element_text(family = base_family, face = "plain", colour = blue, size = base_size, lineheight = 0.9, hjust = 0.5, vjust = 0.5, angle = 0, @@ -27,14 +27,14 @@ theme_tq <- function(base_size = 11, base_family = "") { # Axes axis.line = ggplot2::element_blank(), axis.text = ggplot2::element_text(size = ggplot2::rel(0.8)), - axis.ticks = ggplot2::element_line(color = grey, size = ggplot2::rel(1/3)), + axis.ticks = ggplot2::element_line(color = grey, linewidth = ggplot2::rel(1/3)), axis.title = ggplot2::element_text(size = ggplot2::rel(1.0)), # Panel panel.background = ggplot2::element_rect(fill = white, color = NA), - panel.border = ggplot2::element_rect(fill = NA, size = ggplot2::rel(1/2), color = blue), - panel.grid.major = ggplot2::element_line(color = grey, size = ggplot2::rel(1/3)), - panel.grid.minor = ggplot2::element_line(color = grey, size = ggplot2::rel(1/3)), + panel.border = ggplot2::element_rect(fill = NA, linewidth = ggplot2::rel(1/2), color = blue), + panel.grid.major = ggplot2::element_line(color = grey, linewidth = ggplot2::rel(1/3)), + panel.grid.minor = ggplot2::element_line(color = grey, linewidth = ggplot2::rel(1/3)), panel.grid.minor.x = ggplot2::element_blank(), panel.spacing = ggplot2::unit(.75, "cm"), @@ -70,12 +70,12 @@ theme_tq_dark <- function(base_size = 11, base_family = "") { ggplot2::theme( # Axes - axis.ticks = ggplot2::element_line(color = blue, size = ggplot2::rel(1/3)), + axis.ticks = ggplot2::element_line(color = blue, linewidth = ggplot2::rel(1/3)), # Panel panel.background = ggplot2::element_rect(fill = grey, color = NA), - panel.grid.major = ggplot2::element_line(color = white, size = ggplot2::rel(1/3)), - panel.grid.minor = ggplot2::element_line(color = white, size = ggplot2::rel(1/3)), + panel.grid.major = ggplot2::element_line(color = white, linewidth = ggplot2::rel(1/3)), + panel.grid.minor = ggplot2::element_line(color = white, linewidth = ggplot2::rel(1/3)), # Complete theme complete = TRUE @@ -95,12 +95,12 @@ theme_tq_green <- function(base_size = 11, base_family = "") { ggplot2::theme( # Axes - axis.ticks = ggplot2::element_line(color = blue, size = ggplot2::rel(1/3)), + axis.ticks = ggplot2::element_line(color = blue, linewidth = ggplot2::rel(1/3)), # Panel panel.background = ggplot2::element_rect(fill = green, color = NA), - panel.grid.major = ggplot2::element_line(color = white, size = ggplot2::rel(1/3)), - panel.grid.minor = ggplot2::element_line(color = white, size = ggplot2::rel(1/3)), + panel.grid.major = ggplot2::element_line(color = white, linewidth = ggplot2::rel(1/3)), + panel.grid.minor = ggplot2::element_line(color = white, linewidth = ggplot2::rel(1/3)), # Complete theme complete = TRUE diff --git a/man/anomalize_package.Rd b/man/anomalize-package.Rd similarity index 70% rename from man/anomalize_package.Rd rename to man/anomalize-package.Rd index 5cdc7d7..7ab874e 100644 --- a/man/anomalize_package.Rd +++ b/man/anomalize-package.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/anomalize-package.R \docType{package} -\name{anomalize_package} -\alias{anomalize_package} +\name{anomalize-package} \alias{anomalize-package} -\title{anomalize: Tidy anomaly detection} +\alias{_PACKAGE} +\title{anomalize: Tidy Anomaly Detection} \description{ The 'anomalize' package enables a "tidy" workflow for detecting anomalies in data. The main functions are time_decompose(), anomalize(), and time_recompose(). @@ -17,8 +17,26 @@ two methods for anomaly detection of residuals including using an inner quartile and generalized extreme studentized deviation. These methods are based on those used in the \code{forecast} package and the Twitter \code{AnomalyDetection} package. Refer to the associated functions for specific references for these methods. -} -\details{ + To learn more about \code{anomalize}, start with the vignettes: \code{browseVignettes(package = "anomalize")} } +\seealso{ +Useful links: +\itemize{ + \item \url{https://business-science.github.io/anomalize/} + \item \url{https://github.com/business-science/anomalize} + \item Report bugs at \url{https://github.com/business-science/anomalize/issues} +} + +} +\author{ +\strong{Maintainer}: Matt Dancho \email{mdancho@business-science.io} + +Authors: +\itemize{ + \item Davis Vaughan \email{dvaughan@business-science.io} +} + +} +\keyword{internal} diff --git a/man/plot_anomalies.Rd b/man/plot_anomalies.Rd index a789346..a87ccf9 100644 --- a/man/plot_anomalies.Rd +++ b/man/plot_anomalies.Rd @@ -58,7 +58,6 @@ Multiple time series must be grouped using \code{dplyr::group_by()}. library(dplyr) library(ggplot2) -data(tidyverse_cran_downloads) #### SINGLE TIME SERIES #### tidyverse_cran_downloads \%>\% diff --git a/man/plot_anomaly_decomposition.Rd b/man/plot_anomaly_decomposition.Rd index bc3d82b..02da899 100644 --- a/man/plot_anomaly_decomposition.Rd +++ b/man/plot_anomaly_decomposition.Rd @@ -54,8 +54,6 @@ alpha, frequency, and so on should be adjusted. library(dplyr) library(ggplot2) -data(tidyverse_cran_downloads) - tidyverse_cran_downloads \%>\% filter(package == "tidyquant") \%>\% ungroup() \%>\%