Skip to content

Commit

Permalink
deprecate functions dependent on tidymv
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocoretta committed Feb 8, 2025
1 parent abcf13a commit 141ce36
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 185 deletions.
12 changes: 8 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions R/gam.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
#'
Expand Down
99 changes: 7 additions & 92 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions man/plot_polar_smooths-deprecated.Rd

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

58 changes: 0 additions & 58 deletions man/plot_polar_smooths.Rd

This file was deleted.

5 changes: 1 addition & 4 deletions man/predict_polar_gam.Rd

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

17 changes: 16 additions & 1 deletion man/rticulate-deprecated.Rd

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

22 changes: 0 additions & 22 deletions vignettes/polar-gams.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 141ce36

Please sign in to comment.