Skip to content

Commit

Permalink
Remove ggplot2 warnings + redo package doc Remove ggplot2::aes_string…
Browse files Browse the repository at this point in the history
… and use linewidth
  • Loading branch information
olivroy committed Dec 6, 2023
1 parent 1139005 commit b09aef2
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 37 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions R/anomalize-package.R
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
7 changes: 3 additions & 4 deletions R/plot_anomalies.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#' library(dplyr)
#' library(ggplot2)
#'
#' data(tidyverse_cran_downloads)
#'
#' #### SINGLE TIME SERIES ####
#' tidyverse_cran_downloads %>%
Expand Down Expand Up @@ -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) {
Expand All @@ -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) +
Expand Down
6 changes: 2 additions & 4 deletions R/plot_anomaly_decomposition.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#' library(dplyr)
#' library(ggplot2)
#'
#' data(tidyverse_cran_downloads)
#'
#' tidyverse_cran_downloads %>%
#' filter(package == "tidyquant") %>%
#' ungroup() %>%
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions R/tidyquant_theme_compat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 23 additions & 5 deletions man/anomalize_package.Rd → man/anomalize-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/plot_anomalies.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/plot_anomaly_decomposition.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b09aef2

Please sign in to comment.