diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index de5a6e8..22eb609 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ Version: 0.2.0 -Date: 2024-10-23 01:14:59 UTC -SHA: 7d534be302fc0f099dcd42a4983b0b49d0bf3ca2 +Date: 2024-10-23 12:54:05 UTC +SHA: 50e5591427422b48f58d03028ae9285bda4a1e21 diff --git a/DESCRIPTION b/DESCRIPTION index 2fe5d78..196a602 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,5 +34,6 @@ Suggests: knitr, rmarkdown, stats, - ggplot2 + ggplot2, + tidyselect VignetteBuilder: knitr diff --git a/R/auto-rw30.R b/R/auto-rw30.R index af1cef9..947a612 100644 --- a/R/auto-rw30.R +++ b/R/auto-rw30.R @@ -18,24 +18,13 @@ #' `num_steps`, `mu`, and `sd` are attached to the tibble. #' #' @examples -#' library(ggplot2) -#' #' # Generate random walks and print the result #' set.seed(123) #' rw30() #' #' set.seed(123) #' rw30() |> -#' ggplot(aes(x = x, y = y, color = walk_number, group = walk_number)) + -#' geom_line() + -#' theme_minimal() + -#' theme(legend.position = "none") + -#' labs( -#' title = "30 Random Walks", -#' x = "Step", -#' y = "Value", -#' color = "Walk Number" -#' ) +#' visualize_walks() #' #' @name rw30 NULL diff --git a/R/gen-brown-motion-geometric.R b/R/gen-brown-motion-geometric.R index 49324c2..8e79672 100644 --- a/R/gen-brown-motion-geometric.R +++ b/R/gen-brown-motion-geometric.R @@ -43,18 +43,12 @@ #' of class matrix will be returned. #' #' @examples -#' library(ggplot2) -#' #' set.seed(123) #' geometric_brownian_motion() #' #' set.seed(123) -#' geometric_brownian_motion() |> -#' ggplot(aes(x = x, y = y, group = walk_number, color = walk_number)) + -#' geom_line() + -#' labs(title = "Geometric Brownian Motion", x = "Time", y = "Value") + -#' theme_minimal() + -#' theme(legend.position = "none") +#' geometric_brownian_motion(.num_walks = 5) |> +#' visualize_walks() #' #' @return #' A tibble/matrix diff --git a/R/gen-brown-motion.R b/R/gen-brown-motion.R index aa3b326..a351f94 100644 --- a/R/gen-brown-motion.R +++ b/R/gen-brown-motion.R @@ -32,18 +32,12 @@ #' of class matrix will be returned. #' #' @examples -#' library(ggplot2) -#' #' set.seed(123) #' brownian_motion() #' #' set.seed(123) -#' brownian_motion() |> -#' ggplot(aes(x = x, y = y, group = walk_number, color = walk_number)) + -#' geom_line() + -#' labs(title = "Brownian Motion", x = "Time", y = "Value") + -#' theme_minimal() + -#' theme(legend.position = "none") +#' brownian_motion(.num_walks = 5) |> +#' visualize_walks() #' #' @return #' A tibble/matrix diff --git a/R/gen-discrete-walk.R b/R/gen-discrete-walk.R index 9a161f5..13ee1ca 100644 --- a/R/gen-discrete-walk.R +++ b/R/gen-discrete-walk.R @@ -33,12 +33,9 @@ #' discrete_walk() #' #' set.seed(123) -#' discrete_walk(.num_walks = 30, .n = 250, .upper_probability = 0.55) |> -#' ggplot(aes(x = x, y = cum_sum)) + -#' geom_line(aes(group = walk_number), alpha = .618, color = "steelblue") + -#' theme_minimal() + -#' theme(legend.position = "none") + -#' geom_smooth(method = "lm", se = FALSE) +#' discrete_walk(.num_walks = 10, .n = 250, .upper_probability = 0.51, +#' .initial_value = 100) |> +#' visualize_walks() #' #' @return #' A tibble containing the simulated walks, with columns for the walk number, diff --git a/R/gen-random-normal-walk-drift.R b/R/gen-random-normal-walk-drift.R index 6a497ae..1502044 100644 --- a/R/gen-random-normal-walk-drift.R +++ b/R/gen-random-normal-walk-drift.R @@ -24,16 +24,10 @@ #' @param .initial_value A numeric value indicating the initial value of the walks. Default is 0. #' #' @examples -#' library(ggplot2) -#' #' set.seed(123) -#' walks <- random_normal_drift_walk(.num_walks = 10, .n = 50, .mu = 0, .sd = 1.2, -#' .drift = 0.05) -#' ggplot(walks, aes(x = x, y = y, group = walk_number, color = walk_number)) + -#' geom_line() + -#' labs(title = "Random Walks with Drift", x = "Time", y = "Value") + -#' theme_minimal() + -#' theme(legend.position = "none") +#' random_normal_drift_walk(.num_walks = 10, .n = 50, .mu = 0, .sd = 1.2, +#' .drift = 0.05, .initial_value = 100) |> +#' visualize_walks() #' #' @return A tibble in long format with columns `walk_number`, `x` (step index), #' and `y` (walk value). The tibble has attributes for the number of walks, diff --git a/R/gen-random-normal-walk.R b/R/gen-random-normal-walk.R index 994e94d..643067c 100644 --- a/R/gen-random-normal-walk.R +++ b/R/gen-random-normal-walk.R @@ -53,12 +53,8 @@ #' random_normal_walk(.num_walks = 10, .n = 50, .samp = FALSE) #' #' set.seed(123) -#' random_normal_walk(.num_walks = 2, .n = 100) |> -#' ggplot(aes(x = x, y = y, group = walk_number, color = walk_number)) + -#' geom_line() + -#' labs(title = "Random Normal Walk", x = "Time", y = "Value") + -#' theme_minimal() + -#' theme(legend.position = "none") +#' random_normal_walk(.num_walks = 2, .n = 100, .initial_value = 100) |> +#' visualize_walks() #' #' @name random_normal_walk NULL diff --git a/R/helpers.R b/R/helpers.R index d8ec5e6..1468b3c 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -239,7 +239,7 @@ std_cum_sum_augment <- function(.data, calls <- purrr::set_names(calls, newname) - ret <- tibble::as_tibble(dplyr::mutate(.data, !!!calls)) + ret <- dplyr::as_tibble(dplyr::mutate(.data, !!!calls)) return(ret) } @@ -307,7 +307,7 @@ std_cum_prod_augment <- function(.data, calls <- purrr::set_names(calls, newname) - ret <- tibble::as_tibble(dplyr::mutate(.data, !!!calls)) + ret <- dplyr::as_tibble(dplyr::mutate(.data, !!!calls)) return(ret) } @@ -375,7 +375,7 @@ std_cum_min_augment <- function(.data, calls <- purrr::set_names(calls, newname) - ret <- tibble::as_tibble(dplyr::mutate(.data, !!!calls)) + ret <- dplyr::as_tibble(dplyr::mutate(.data, !!!calls)) return(ret) } @@ -443,7 +443,7 @@ std_cum_max_augment <- function(.data, calls <- purrr::set_names(calls, newname) - ret <- tibble::as_tibble(dplyr::mutate(.data, !!!calls)) + ret <- dplyr::as_tibble(dplyr::mutate(.data, !!!calls)) return(ret) } @@ -511,7 +511,7 @@ std_cum_mean_augment <- function(.data, calls <- purrr::set_names(calls, newname) - ret <- tibble::as_tibble(dplyr::mutate(.data, !!!calls)) + ret <- dplyr::as_tibble(dplyr::mutate(.data, !!!calls)) return(ret) } diff --git a/R/plt-visualize-walks.R b/R/plt-visualize-walks.R index 94f47eb..846209b 100644 --- a/R/plt-visualize-walks.R +++ b/R/plt-visualize-walks.R @@ -26,7 +26,7 @@ #' liking. #' #' You can also choose whether you want the visualization to be interactive or -#' not by setting `.interactive` to TRUE. The function uses the {ggiraph} +#' not by setting `.interactive` to TRUE. The function uses the `ggiraph` #' package for making the patches interactive. #' #' If you want to visualize only one of the attributes, you can choose use one of @@ -61,17 +61,17 @@ #' #' # Use the function with an input that has alternatives for y #' set.seed(123) -#' random_normal_walk() |> +#' random_normal_walk(.num_walks = 5, .initial_value = 100) |> #' visualize_walks() #' #' # Use the function to create interactive visualizations #' set.seed(123) -#' random_normal_walk() |> +#' random_normal_walk(.num_walks = 5, .initial_value = 100) |> #' visualize_walks(.interactive = TRUE) #' #' # Use .pluck to pick just one visualization #' set.seed(123) -#' random_normal_walk() |> +#' random_normal_walk(.num_walks = 5, .initial_value = 100) |> #' visualize_walks(.pluck = "cum_sum") #' #' @name visualize_walks diff --git a/man/brownian_motion.Rd b/man/brownian_motion.Rd index 2e602f7..442af29 100644 --- a/man/brownian_motion.Rd +++ b/man/brownian_motion.Rd @@ -51,18 +51,12 @@ walk processes in general. It is a useful tool in probability theory and statistical analysis. } \examples{ -library(ggplot2) - set.seed(123) brownian_motion() set.seed(123) -brownian_motion() |> - ggplot(aes(x = x, y = y, group = walk_number, color = walk_number)) + - geom_line() + - labs(title = "Brownian Motion", x = "Time", y = "Value") + - theme_minimal() + - theme(legend.position = "none") +brownian_motion(.num_walks = 5) |> + visualize_walks() } \seealso{ diff --git a/man/discrete_walk.Rd b/man/discrete_walk.Rd index bdb8292..11adb8d 100644 --- a/man/discrete_walk.Rd +++ b/man/discrete_walk.Rd @@ -52,12 +52,9 @@ set.seed(123) discrete_walk() set.seed(123) -discrete_walk(.num_walks = 30, .n = 250, .upper_probability = 0.55) |> -ggplot(aes(x = x, y = cum_sum)) + - geom_line(aes(group = walk_number), alpha = .618, color = "steelblue") + - theme_minimal() + - theme(legend.position = "none") + - geom_smooth(method = "lm", se = FALSE) +discrete_walk(.num_walks = 10, .n = 250, .upper_probability = 0.51, +.initial_value = 100) |> +visualize_walks() } \seealso{ diff --git a/man/geometric_brownian_motion.Rd b/man/geometric_brownian_motion.Rd index ab40322..1a1b2e9 100644 --- a/man/geometric_brownian_motion.Rd +++ b/man/geometric_brownian_motion.Rd @@ -66,18 +66,12 @@ of a GBM process. It can be used to analyze the behavior of financial assets and to make informed investment decisions. } \examples{ -library(ggplot2) - set.seed(123) geometric_brownian_motion() set.seed(123) -geometric_brownian_motion() |> - ggplot(aes(x = x, y = y, group = walk_number, color = walk_number)) + - geom_line() + - labs(title = "Geometric Brownian Motion", x = "Time", y = "Value") + - theme_minimal() + - theme(legend.position = "none") +geometric_brownian_motion(.num_walks = 5) |> + visualize_walks() } \seealso{ diff --git a/man/random_normal_drift_walk.Rd b/man/random_normal_drift_walk.Rd index 9c306fe..4d7ad39 100644 --- a/man/random_normal_drift_walk.Rd +++ b/man/random_normal_drift_walk.Rd @@ -44,16 +44,10 @@ Each walk is generated using a normal distribution for the steps, with an additional drift term added to each step. } \examples{ -library(ggplot2) - set.seed(123) -walks <- random_normal_drift_walk(.num_walks = 10, .n = 50, .mu = 0, .sd = 1.2, - .drift = 0.05) -ggplot(walks, aes(x = x, y = y, group = walk_number, color = walk_number)) + - geom_line() + - labs(title = "Random Walks with Drift", x = "Time", y = "Value") + - theme_minimal() + - theme(legend.position = "none") +random_normal_drift_walk(.num_walks = 10, .n = 50, .mu = 0, .sd = 1.2, + .drift = 0.05, .initial_value = 100) |> + visualize_walks() } \seealso{ diff --git a/man/random_normal_walk.Rd b/man/random_normal_walk.Rd index b9dc7a3..dd12eb2 100644 --- a/man/random_normal_walk.Rd +++ b/man/random_normal_walk.Rd @@ -73,12 +73,8 @@ set.seed(123) random_normal_walk(.num_walks = 10, .n = 50, .samp = FALSE) set.seed(123) -random_normal_walk(.num_walks = 2, .n = 100) |> - ggplot(aes(x = x, y = y, group = walk_number, color = walk_number)) + - geom_line() + - labs(title = "Random Normal Walk", x = "Time", y = "Value") + - theme_minimal() + - theme(legend.position = "none") +random_normal_walk(.num_walks = 2, .n = 100, .initial_value = 100) |> + visualize_walks() } \seealso{ diff --git a/man/rw30.Rd b/man/rw30.Rd index 8fbf24b..d56bd6e 100644 --- a/man/rw30.Rd +++ b/man/rw30.Rd @@ -21,24 +21,13 @@ Each walk is generated independently and stored in a tibble. The resulting tibble is then pivoted into a long format for easier analysis. } \examples{ -library(ggplot2) - # Generate random walks and print the result set.seed(123) rw30() set.seed(123) rw30() |> - ggplot(aes(x = x, y = y, color = walk_number, group = walk_number)) + - geom_line() + - theme_minimal() + - theme(legend.position = "none") + - labs( - title = "30 Random Walks", - x = "Step", - y = "Value", - color = "Walk Number" - ) + visualize_walks() } \author{ diff --git a/man/visualize_walks.Rd b/man/visualize_walks.Rd index 6872482..18d70ed 100644 --- a/man/visualize_walks.Rd +++ b/man/visualize_walks.Rd @@ -52,7 +52,7 @@ but you can set \code{.alpha} if the default value of 0.7 isn't to your liking. You can also choose whether you want the visualization to be interactive or -not by setting \code{.interactive} to TRUE. The function uses the {ggiraph} +not by setting \code{.interactive} to TRUE. The function uses the \code{ggiraph} package for making the patches interactive. If you want to visualize only one of the attributes, you can choose use one of @@ -72,17 +72,17 @@ rw30() |> # Use the function with an input that has alternatives for y set.seed(123) -random_normal_walk() |> +random_normal_walk(.num_walks = 5, .initial_value = 100) |> visualize_walks() # Use the function to create interactive visualizations set.seed(123) -random_normal_walk() |> +random_normal_walk(.num_walks = 5, .initial_value = 100) |> visualize_walks(.interactive = TRUE) # Use .pluck to pick just one visualization set.seed(123) -random_normal_walk() |> +random_normal_walk(.num_walks = 5, .initial_value = 100) |> visualize_walks(.pluck = "cum_sum") }