Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve gam visualization #157

Merged
merged 6 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/update-citation-cff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# The action runs when:
# - A new release is published
# - The DESCRIPTION or inst/CITATION are modified
# - Can be run manually
# For customizing the triggers, visit https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
release:
types: [published]
push:
branches: [master, main]
paths:
- DESCRIPTION
- inst/CITATION
workflow_dispatch:

name: Update CITATION.cff

jobs:
update-citation-cff:
runs-on: macos-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::cffr
any::V8

- name: Update CITATION.cff
run: |

library(cffr)

# Customize with your own code
# See https://docs.ropensci.org/cffr/articles/cffr.html

# Write your own keys
mykeys <- list()

# Create your CITATION.cff file
cff_write(keys = mykeys)

shell: Rscript {0}

- name: Commit results
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add CITATION.cff
git commit -m 'Update CITATION.cff' || echo "No changes to commit"
git push origin || echo "No changes to commit"



2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: trias
Title: Process Data for the Project Tracking Invasive Alien Species
(TrIAS)
Version: 3.0.1
Version: 3.0.2
Authors@R: c(
person("Damiano", "Oldoni", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-3445-7562")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# trias 3.0.2

- Improve `apply_gam()` to avoid emerging status change for negligible near zero values (#150).
- Show all emerging status values in the legend of the plots returned by `apply_gam()` (#152).
- `CITATION.cff` is updated automatically via GitHub Actions (#151).

# trias 3.0.1

- Function `get_cred()` is not exported anymore (#146). Internally used only.
Expand Down
36 changes: 21 additions & 15 deletions R/apply_gam.R
Original file line number Diff line number Diff line change
Expand Up @@ -668,19 +668,19 @@ apply_gam <- function(df,
deriv1 %>%
dplyr::filter(!is.na(!!dplyr::sym(year))) %>%
dplyr::mutate(em1 = dplyr::case_when(
.data$lower_ci < 0 & .data$upper_ci <= 0 ~ -1,
.data$lower_ci < 0 & .data$upper_ci > 0 ~ 0,
.data$lower_ci >= 0 & .data$upper_ci > 0 ~ 1
.data$lower_ci < 0 & .data$upper_ci <= - 0.01 ~ -1,
.data$lower_ci < 0.01 & .data$upper_ci > - 0.01 ~ 0,
.data$lower_ci >= 0.01 & .data$upper_ci > 0 ~ 1
)) %>%
dplyr::select(!!dplyr::sym(year), "em1") %>%
dplyr::mutate(!!dplyr::sym(year) := round(!!dplyr::sym(year)))

em2 <- deriv2 %>%
dplyr::filter(!is.na(!!dplyr::sym(year))) %>%
dplyr::mutate(em2 = dplyr::case_when(
.data$lower_ci < 0 & .data$upper_ci <= 0 ~ -1,
.data$lower_ci < 0 & .data$upper_ci > 0 ~ 0,
.data$lower_ci >= 0 & .data$upper_ci > 0 ~ 1
.data$lower_ci < 0 & .data$upper_ci <= - 0.01 ~ -1,
.data$lower_ci < 0.01 & .data$upper_ci > - 0.01 ~ 0,
.data$lower_ci >= 0.01 & .data$upper_ci > 0 ~ 1
)) %>%
dplyr::select(!!dplyr::sym(year), "em2") %>%
dplyr::mutate(!!dplyr::sym(year) := round(!!dplyr::sym(year)))
Expand Down Expand Up @@ -824,6 +824,7 @@ apply_gam <- function(df,
#' are returned. Default: \code{FALSE}.
#' @return a ggplot2 plot object.
#' @importFrom dplyr .data %>%
#' @noRd
plot_ribbon_em <- function(df_plot,
x_axis = "year",
y_axis = "obs",
Expand Down Expand Up @@ -862,17 +863,22 @@ plot_ribbon_em <- function(df_plot,
) +
ggplot2::geom_line(ggplot2::aes(x = .data$year, y = .data$fit),
color = "grey50") +
ggplot2::geom_point(ggplot2::aes(
x = .data$year,
y = .data$fit,
color = factor(.data$em_status)
),
size = 2
) +
ggplot2::geom_point(
mapping = ggplot2::aes(
x = .data$year,
y = .data$fit,
color = factor(
.data$em_status,
levels = names(colors_em)
)
),
size = 2,
show.legend = TRUE) +
ggplot2::scale_colour_manual(
values = colors_em,
labels = labels_em,
name = "Emerging status"
name = "Emerging status",
drop = FALSE
) +
ggplot2::theme(plot.title = ggplot2::element_text(size = 10))
} else {
Expand All @@ -889,7 +895,7 @@ plot_ribbon_em <- function(df_plot,

#' Add annotation when status cannot be assessed
#'
#' Internal function to be used when GAM cannot be applied to it doesn't
#' Internal function to be used when GAM cannot be applied as it doesn't
#' converge.
#'
#' @param plot_obs ggplot2 plot object showing the observations.
Expand Down
40 changes: 0 additions & 40 deletions man/plot_ribbon_em.Rd

This file was deleted.

Loading