No flags found
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
a615e6a
... +5 ...
de0d706
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
1 | 1 | #' Detect anomalies using the tidyverse |
|
2 | 2 | #' |
|
3 | + | #' The `anomalize()` function is used to detect outliers in a distribution |
|
4 | + | #' with no trend or seasonality present. It takes the output of [time_decompose()], |
|
5 | + | #' which has be de-trended and applies anomaly detection methods to identify outliers. |
|
6 | + | #' |
|
3 | 7 | #' @inheritParams time_apply |
|
4 | 8 | #' @param data A `tibble` or `tbl_time` object. |
|
5 | 9 | #' @param method The anomaly detection method. One of `"iqr"` or `"gesd"`. |
17 | 21 | #' @return Returns a `tibble` / `tbl_time` object or list depending on the value of `verbose`. |
|
18 | 22 | #' |
|
19 | 23 | #' @details |
|
20 | - | #' The `anomalize()` function is used to detect outliers in a distribution |
|
21 | - | #' with no trend or seasonality present. The return has three columns: |
|
24 | + | #' The return has three columns: |
|
22 | 25 | #' "remainder_l1" (lower limit for anomalies), "remainder_l2" (upper limit for |
|
23 | 26 | #' anomalies), and "anomaly" (Yes/No). |
|
24 | 27 | #' |
1 | - | # tidyquant funtions copied to remove dependency on tidyquant |
|
1 | + | # tidyquant functions copied to remove dependency on tidyquant |
|
2 | + | ||
3 | + | #' @importFrom ggplot2 %+replace% |
|
2 | 4 | ||
3 | 5 | theme_tq <- function(base_size = 11, base_family = "") { |
|
4 | 6 |
9 | 11 | grey <- "grey80" |
|
10 | 12 | ||
11 | 13 | # Starts with theme_grey and then modify some parts |
|
12 | - | theme_grey(base_size = base_size, base_family = base_family) %+replace% |
|
13 | - | theme( |
|
14 | + | ggplot2::theme_grey(base_size = base_size, base_family = base_family) %+replace% |
|
15 | + | ggplot2::theme( |
|
14 | 16 | ||
15 | 17 | # Base Inherited Elements |
|
16 | - | line = element_line(colour = blue, size = 0.5, linetype = 1, |
|
17 | - | lineend = "butt"), |
|
18 | - | rect = element_rect(fill = white, colour = blue, |
|
19 | - | size = 0.5, linetype = 1), |
|
20 | - | text = element_text(family = base_family, face = "plain", |
|
21 | - | colour = blue, size = base_size, |
|
22 | - | lineheight = 0.9, hjust = 0.5, vjust = 0.5, angle = 0, |
|
23 | - | margin = margin(), debug = FALSE), |
|
18 | + | line = ggplot2::element_line(colour = blue, size = 0.5, linetype = 1, |
|
19 | + | lineend = "butt"), |
|
20 | + | rect = ggplot2::element_rect(fill = white, colour = blue, |
|
21 | + | size = 0.5, linetype = 1), |
|
22 | + | text = ggplot2::element_text(family = base_family, face = "plain", |
|
23 | + | colour = blue, size = base_size, |
|
24 | + | lineheight = 0.9, hjust = 0.5, vjust = 0.5, angle = 0, |
|
25 | + | margin = ggplot2::margin(), debug = FALSE), |
|
24 | 26 | ||
25 | 27 | # Axes |
|
26 | - | axis.line = element_blank(), |
|
27 | - | axis.text = element_text(size = rel(0.8)), |
|
28 | - | axis.ticks = element_line(color = grey, size = rel(1/3)), |
|
29 | - | axis.title = element_text(size = rel(1.0)), |
|
28 | + | axis.line = ggplot2::element_blank(), |
|
29 | + | axis.text = ggplot2::element_text(size = ggplot2::rel(0.8)), |
|
30 | + | axis.ticks = ggplot2::element_line(color = grey, size = ggplot2::rel(1/3)), |
|
31 | + | axis.title = ggplot2::element_text(size = ggplot2::rel(1.0)), |
|
30 | 32 | ||
31 | 33 | # Panel |
|
32 | - | panel.background = element_rect(fill = white, color = NA), |
|
33 | - | panel.border = element_rect(fill = NA, size = rel(1/2), color = blue), |
|
34 | - | panel.grid.major = element_line(color = grey, size = rel(1/3)), |
|
35 | - | panel.grid.minor = element_line(color = grey, size = rel(1/3)), |
|
36 | - | panel.grid.minor.x = element_blank(), |
|
37 | - | panel.spacing = unit(.75, "cm"), |
|
34 | + | panel.background = ggplot2::element_rect(fill = white, color = NA), |
|
35 | + | panel.border = ggplot2::element_rect(fill = NA, size = ggplot2::rel(1/2), color = blue), |
|
36 | + | panel.grid.major = ggplot2::element_line(color = grey, size = ggplot2::rel(1/3)), |
|
37 | + | panel.grid.minor = ggplot2::element_line(color = grey, size = ggplot2::rel(1/3)), |
|
38 | + | panel.grid.minor.x = ggplot2::element_blank(), |
|
39 | + | panel.spacing = ggplot2::unit(.75, "cm"), |
|
38 | 40 | ||
39 | 41 | # Legend |
|
40 | - | legend.key = element_rect(fill = white, color = NA), |
|
42 | + | legend.key = ggplot2::element_rect(fill = white, color = NA), |
|
41 | 43 | legend.position = "bottom", |
|
42 | 44 | ||
43 | 45 | # Strip (Used with multiple panels) |
|
44 | - | strip.background = element_rect(fill = blue, color = blue), |
|
45 | - | strip.text = element_text(color = white, size = rel(0.8)), |
|
46 | + | strip.background = ggplot2::element_rect(fill = blue, color = blue), |
|
47 | + | strip.text = ggplot2::element_text(color = white, size = ggplot2::rel(0.8), margin = ggplot2::margin(t = 5, b = 5)), |
|
46 | 48 | ||
47 | 49 | # Plot |
|
48 | - | plot.title = element_text(size = rel(1.2), hjust = 0, |
|
49 | - | margin = margin(t = 0, r = 0, b = 4, l = 0, unit = "pt")), |
|
50 | - | plot.subtitle = element_text(size = rel(0.9), hjust = 0, |
|
51 | - | margin = margin(t = 0, r = 0, b = 3, l = 0, unit = "pt")), |
|
50 | + | plot.title = ggplot2::element_text(size = ggplot2::rel(1.2), hjust = 0, |
|
51 | + | margin = ggplot2::margin(t = 0, r = 0, b = 4, l = 0, unit = "pt")), |
|
52 | + | plot.subtitle = ggplot2::element_text(size = ggplot2::rel(0.9), hjust = 0, |
|
53 | + | margin = ggplot2::margin(t = 0, r = 0, b = 3, l = 0, unit = "pt")), |
|
54 | + | ||
55 | + | # Complete theme |
|
56 | + | complete = TRUE |
|
57 | + | ) |
|
58 | + | } |
|
59 | + | ||
60 | + | theme_tq_dark <- function(base_size = 11, base_family = "") { |
|
61 | + | ||
62 | + | # Tidyquant colors |
|
63 | + | blue <- "#2c3e50" |
|
64 | + | green <- "#18BC9C" |
|
65 | + | white <- "#FFFFFF" |
|
66 | + | grey <- "grey50" |
|
67 | + | ||
68 | + | # Starts with theme_tq and then invert some colors |
|
69 | + | theme_tq(base_size = base_size, base_family = base_family) %+replace% |
|
70 | + | ggplot2::theme( |
|
71 | + | ||
72 | + | # Axes |
|
73 | + | axis.ticks = ggplot2::element_line(color = blue, size = ggplot2::rel(1/3)), |
|
74 | + | ||
75 | + | # Panel |
|
76 | + | panel.background = ggplot2::element_rect(fill = grey, color = NA), |
|
77 | + | panel.grid.major = ggplot2::element_line(color = white, size = ggplot2::rel(1/3)), |
|
78 | + | panel.grid.minor = ggplot2::element_line(color = white, size = ggplot2::rel(1/3)), |
|
79 | + | ||
80 | + | # Complete theme |
|
81 | + | complete = TRUE |
|
82 | + | ) |
|
83 | + | } |
|
84 | + | ||
85 | + | theme_tq_green <- function(base_size = 11, base_family = "") { |
|
86 | + | ||
87 | + | # Tidyquant colors |
|
88 | + | blue <- "#2c3e50" |
|
89 | + | green <- "#18BC9C" |
|
90 | + | white <- "#FFFFFF" |
|
91 | + | grey <- "grey80" |
|
92 | + | ||
93 | + | # Starts with theme_tq and then invert some colors |
|
94 | + | theme_tq(base_size = base_size, base_family = base_family) %+replace% |
|
95 | + | ggplot2::theme( |
|
96 | + | ||
97 | + | # Axes |
|
98 | + | axis.ticks = ggplot2::element_line(color = blue, size = ggplot2::rel(1/3)), |
|
99 | + | ||
100 | + | # Panel |
|
101 | + | panel.background = ggplot2::element_rect(fill = green, color = NA), |
|
102 | + | panel.grid.major = ggplot2::element_line(color = white, size = ggplot2::rel(1/3)), |
|
103 | + | panel.grid.minor = ggplot2::element_line(color = white, size = ggplot2::rel(1/3)), |
|
52 | 104 | ||
53 | 105 | # Complete theme |
|
54 | 106 | complete = TRUE |
|
55 | 107 | ) |
|
56 | 108 | } |
|
57 | 109 | ||
110 | + | scale_color_tq <- function(..., theme = "light") { |
|
111 | + | ||
112 | + | pal <- switch(theme, |
|
113 | + | "light" = unname(palette_light()) %>% rep(100), |
|
114 | + | "dark" = unname(palette_dark()) %>% rep(100), |
|
115 | + | "green" = unname(palette_green() %>% rep(100)) |
|
116 | + | ) |
|
117 | + | ||
118 | + | ggplot2::scale_color_manual(values = pal) |
|
119 | + | } |
|
120 | + | ||
121 | + | palette_light <- function() { |
|
122 | + | c( |
|
123 | + | blue = "#2c3e50", # blue |
|
124 | + | red = "#e31a1c", # red |
|
125 | + | green = "#18BC9C", # green |
|
126 | + | yellow = "#CCBE93", # yellow |
|
127 | + | steel_blue = "#a6cee3", # steel_blue |
|
128 | + | navy_blue = "#1f78b4", # navy_blue |
|
129 | + | light_green = "#b2df8a", # light_green |
|
130 | + | pink = "#fb9a99", # pink |
|
131 | + | light_orange = "#fdbf6f", # light_orange |
|
132 | + | orange = "#ff7f00", # orange |
|
133 | + | light_purple = "#cab2d6", # light_purple |
|
134 | + | purple = "#6a3d9a" # purple |
|
135 | + | ) %>% toupper() |
|
136 | + | } |
|
137 | + | ||
138 | + | palette_dark <- function() { |
|
139 | + | # Brighter version of palette_light |
|
140 | + | c( |
|
141 | + | blue = "#0055AA", # blue |
|
142 | + | red = "#C40003", # red |
|
143 | + | green = "#00C19B", # green |
|
144 | + | yellow = "#EAC862", # yellow |
|
145 | + | steel_blue = "#7FD2FF", # steel_blue |
|
146 | + | navy_blue = "#007ED3", # navy_blue |
|
147 | + | light_green = "#b2df8a", # light_green |
|
148 | + | pink = "#FFACAA", # pink |
|
149 | + | light_orange = "#FF9D1E", # light_orange |
|
150 | + | lime_green = "#C3EF00", # lime_green |
|
151 | + | light_purple = "#cab2d6", # light_purple |
|
152 | + | purple = "#894FC6" # purple |
|
153 | + | ) %>% toupper() |
|
154 | + | } |
|
155 | + | ||
156 | + | palette_green <- function() { |
|
157 | + | # Green compatible version of palette_light |
|
158 | + | c( |
|
159 | + | blue = "#0055AA", # blue |
|
160 | + | red = "#C40003", # red |
|
161 | + | yellow = "#EAC862", # yellow |
|
162 | + | steel_blue = "#7FD2FF", # steel_blue |
|
163 | + | navy_blue = "#007ED3", # navy_blue |
|
164 | + | creme = "#F6F4F3", # creme |
|
165 | + | pink = "#FFACAA", # pink |
|
166 | + | light_orange = "#FF9D1E", # light_orange |
|
167 | + | lime_green = "#C3EF00", # lime_green |
|
168 | + | light_purple = "#cab2d6", # light_purple |
|
169 | + | purple = "#894FC6", # purple |
|
170 | + | brown = "#592E2E" # brown |
|
171 | + | ) %>% toupper() |
|
172 | + | } |
|
173 | + | ||
58 | 174 | palette_light <- function() { |
|
59 | 175 | c( |
|
60 | 176 | blue = "#2c3e50", # blue |
Files | Coverage |
---|---|
R | -6.27% 79.36% |
Project Totals (15 files) | 79.36% |
de0d706
1a15d5d
e984b10
fed2f3c
4bd577f
81cb76f
a615e6a