diff --git a/DESCRIPTION b/DESCRIPTION index 3767659..219c0b1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,23 +16,27 @@ BugReports: https://github.com/stefanocoretta/rticulate/issues Depends: R (>= 3.0.0) Encoding: UTF-8 LazyData: true -Imports: dplyr, +Imports: cli, + dplyr, ggplot2, glue, + gsignal, magrittr, mgcv, + pracma, purrr, readr, rlang, stats, tibble, - tidygam, tidyr, tidyselect -RoxygenNote: 7.2.1 +RoxygenNote: 7.3.2 Suggests: knitr, + rcartocolor, rmarkdown, - stringr + stringr, + tidyverse VignetteBuilder: knitr Language: en-US License: MIT + file LICENSE diff --git a/R/gam.R b/R/gam.R index 9a4876c..81c4417 100644 --- a/R/gam.R +++ b/R/gam.R @@ -52,10 +52,7 @@ polar_gam <- function(formula, data, origin = NULL, fan_lines = c(10, 25), AR_st #' #' It returns a tibble with the predictions from all the terms in a \link[rticulate]{polar_gam} model. #' -#' The function behaves like \link[tidymv]{predict_gam} but it converts the -#' coordinates from polar to cartesian automatically. Check -#' \code{vignette("predict-gam", package = "tidymv")} to an overview of the -#' predict method. +#' The function converts the coordinates from polar to cartesian automatically. #' #' To see an example of plotting, see the examples in \link[rticulate]{geom_polar_ci}. #' diff --git a/R/plot.R b/R/plot.R index e53cc57..35ce858 100644 --- a/R/plot.R +++ b/R/plot.R @@ -44,105 +44,20 @@ plot_tongue <- function(data, geom = "line", ..., palate = NULL, palate_col = "g #' #' It plots the smooths of a polar GAM fitted with \code{polar_gam()}. #' -#' @inheritParams tidymv::plot_smooths -#' @inheritParams transform_coord #' @param split Columns to separate as a named list. #' @param sep Separator between columns (default is \code{"\\."}, which is the default with \code{}). If character, it is interpreted as a regular expression. #' #' @return An object of class \code{\link[ggplot2]{ggplot}}. #' -#' @examples -#' \donttest{ -#' library(dplyr) -#' tongue_it01 <- filter(tongue, speaker == "it01") -#' pgam <- polar_gam(Y ~ s(X, by = as.factor(label)), data = tongue_it01) -#' -#' plot_polar_smooths(pgam, X, label) -#' } +#' @name plot_polar_smooths-deprecated +#' @seealso \code{\link{rticulate-deprecated}} +#' @keywords internal +NULL + +#' @rdname rticulate-deprecated #' @export plot_polar_smooths <- function(model, series, comparison = NULL, origin = NULL, facet_terms = NULL, conditions = NULL, exclude_random = TRUE, series_length = 100, split = NULL, sep = "\\.", time_series) { - if(!missing(time_series)) { - warning("This argument has been deprecated and will be removed in the future. Please use `series` instead.") - - series_q = dplyr::enquo(time_series) - } else { - time_series = NULL - series_q <- dplyr::enquo(series) - } - - comparison_q <- dplyr::enquo(comparison) - facet_terms_q <- dplyr::enquo(facet_terms) - if (rlang::quo_is_null(comparison_q)) { - comparison_q <- NULL - } - if (rlang::quo_is_null(facet_terms_q)) { - facet_terms_q <- NULL - } - outcome_q <- model$formula[[2]] - - predicted_tbl <- tidymv::get_gam_predictions(model, !!series_q, conditions, exclude_random = exclude_random, series_length = series_length, split = split, sep = sep) - - if (is.null(origin)) { - origin <- model$polar_origin - } - - cartesian_predicted <- predicted_tbl %>% - transform_coord( - to = "cartesian", - origin = origin, - use_XY = TRUE - ) - - cartesian_ci <- transform_ci( - predicted_tbl, - origin = origin - ) - - smooths_plot <- cartesian_predicted %>% - ggplot2::ggplot( - ggplot2::aes_string( - rlang::quo_name(series_q), rlang::quo_name(outcome_q) - ) - ) + - {if (!is.null(comparison_q)) { - ggplot2::geom_polygon( - data = cartesian_ci, - ggplot2::aes_string( - x = "CI_X", - y = "CI_Y", - fill = rlang::quo_name(comparison_q) - ), - alpha = 0.2 - ) - }} + - {if (is.null(comparison_q)) { - ggplot2::geom_polygon( - data = cartesian_ci, - ggplot2::aes_string( - x = "CI_X", - y = "CI_Y" - ), - alpha = 0.2 - ) - }} + - {if (!is.null(comparison_q)) { - ggplot2::geom_path( - ggplot2::aes_string( - colour = rlang::quo_name(comparison_q), - linetype = rlang::quo_name(comparison_q) - ) - ) - }} + - {if (is.null(comparison_q)) { - ggplot2::geom_path( - ggplot2::aes_string() - ) - }} + - {if (!is.null(facet_terms_q)) { - ggplot2::facet_wrap(facet_terms_q) - }} - - return(smooths_plot) + .Deprecated('vignette("polar-gam", package = "rticulate")', msg = "'plot_polar_smooths()' has been deprecated.") } #' Polar confidence intervals. diff --git a/man/plot_polar_smooths-deprecated.Rd b/man/plot_polar_smooths-deprecated.Rd new file mode 100644 index 0000000..d4924cb --- /dev/null +++ b/man/plot_polar_smooths-deprecated.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{plot_polar_smooths-deprecated} +\alias{plot_polar_smooths-deprecated} +\title{Plot smooths from a polar \code{gam}} +\arguments{ +\item{split}{Columns to separate as a named list.} + +\item{sep}{Separator between columns (default is \code{"\\."}, which is the default with \code{}). If character, it is interpreted as a regular expression.} +} +\value{ +An object of class \code{\link[ggplot2]{ggplot}}. +} +\description{ +It plots the smooths of a polar GAM fitted with \code{polar_gam()}. +} +\seealso{ +\code{\link{rticulate-deprecated}} +} +\keyword{internal} diff --git a/man/plot_polar_smooths.Rd b/man/plot_polar_smooths.Rd deleted file mode 100644 index 4864e84..0000000 --- a/man/plot_polar_smooths.Rd +++ /dev/null @@ -1,58 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R -\name{plot_polar_smooths} -\alias{plot_polar_smooths} -\title{Plot smooths from a polar \code{gam}} -\usage{ -plot_polar_smooths( - model, - series, - comparison = NULL, - origin = NULL, - facet_terms = NULL, - conditions = NULL, - exclude_random = TRUE, - series_length = 100, - split = NULL, - sep = "\\\\.", - time_series -) -} -\arguments{ -\item{model}{A \code{gam} or \code{bam} model object.} - -\item{series}{An unquoted expression indicating the model term that defines the series on which smoothing is applied. This is the term that is displayed on the x-axis when plotting.} - -\item{comparison}{An unquoted expression indicating the model term for which the comparison will be plotted.} - -\item{origin}{The coordinates of the origin as a vector of \code{c(x, y)} coordinates.} - -\item{facet_terms}{An unquoted formula with the terms used for faceting.} - -\item{conditions}{A list of quosures with \code{quos} specifying the levels to plot from the model terms not among \code{series}, \code{comparison}, or \code{facet_terms}.} - -\item{exclude_random}{Whether to exclude random smooths (the default is \code{TRUE}).} - -\item{series_length}{An integer indicating how many values along the time series to use for predicting the outcome term.} - -\item{split}{Columns to separate as a named list.} - -\item{sep}{Separator between columns (default is \code{"\\."}, which is the default with \code{}). If character, it is interpreted as a regular expression.} - -\item{time_series}{Deprecated, use \code{series} instead.} -} -\value{ -An object of class \code{\link[ggplot2]{ggplot}}. -} -\description{ -It plots the smooths of a polar GAM fitted with \code{polar_gam()}. -} -\examples{ -\donttest{ -library(dplyr) -tongue_it01 <- filter(tongue, speaker == "it01") -pgam <- polar_gam(Y ~ s(X, by = as.factor(label)), data = tongue_it01) - -plot_polar_smooths(pgam, X, label) -} -} diff --git a/man/predict_polar_gam.Rd b/man/predict_polar_gam.Rd index d2f0e6d..1093f6d 100644 --- a/man/predict_polar_gam.Rd +++ b/man/predict_polar_gam.Rd @@ -36,10 +36,7 @@ A tibble with predictions from a \link[rticulate]{polar_gam} model. It returns a tibble with the predictions from all the terms in a \link[rticulate]{polar_gam} model. } \details{ -The function behaves like \link[tidymv]{predict_gam} but it converts the -coordinates from polar to cartesian automatically. Check -\code{vignette("predict-gam", package = "tidymv")} to an overview of the -predict method. +The function converts the coordinates from polar to cartesian automatically. To see an example of plotting, see the examples in \link[rticulate]{geom_polar_ci}. } diff --git a/man/rticulate-deprecated.Rd b/man/rticulate-deprecated.Rd index 3bef37b..3b1550a 100644 --- a/man/rticulate-deprecated.Rd +++ b/man/rticulate-deprecated.Rd @@ -1,10 +1,25 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/plot.R, R/rticulate-deprecated.R -\name{geom_polar_ci} +\name{plot_polar_smooths} +\alias{plot_polar_smooths} \alias{geom_polar_ci} \alias{rticulate-deprecated} \title{Deprecated functions in package \pkg{rticulate}.} \usage{ +plot_polar_smooths( + model, + series, + comparison = NULL, + origin = NULL, + facet_terms = NULL, + conditions = NULL, + exclude_random = TRUE, + series_length = 100, + split = NULL, + sep = "\\\\.", + time_series +) + geom_polar_ci(data, group = NULL, ci_z = 1.96, ci_alpha = 0.1) } \value{ diff --git a/vignettes/polar-gams.Rmd b/vignettes/polar-gams.Rmd index ff020cf..e262f61 100644 --- a/vignettes/polar-gams.Rmd +++ b/vignettes/polar-gams.Rmd @@ -53,16 +53,6 @@ summary(polar_place) The output model is in polar coordinates but it contains the origin coordinates so that plotting can be done in cartesian coordinates. -We can now plot the results from the model with `plot_polar_smooths()`. - -```{r plot-smooths} -plot_polar_smooths( - polar_place, - X, - c2_place -) + - theme(legend.position = "top") -``` # Multiple predictors @@ -80,18 +70,6 @@ polar_multi <- polar_gam( summary(polar_multi) ``` -Th argument `facet_terms` can be used to specify the terms for the facets. -If you desire to facet by more then one term, just add multiple terms separated by `+` (for example, `facet_terms = vowel + voicing`; only terms that have been included in the model can be used for faceting, for more examples see the vignettes of the tidymv package). - -```{r plot-smooths-2} -plot_polar_smooths( - polar_multi, - X, - c2_place, - facet_terms = vowel -) + - theme(legend.position = "top") -``` # Extract all predicted values