Skip to content

Commit

Permalink
Merge pull request #232 from PlanktonTeam/EOVplots
Browse files Browse the repository at this point in the history
EOV plots
  • Loading branch information
jaseeverett committed Sep 7, 2023
2 parents 8b8bab5 + 12fc7f0 commit 7eac3e6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,6 +1,6 @@
Package: planktonr
Title: Analysis and visualisation of plankton data
Version: 0.5.6.0000
Version: 0.5.7.0000
Authors@R: c(
person("Jason D.", "Everett", , "jase.everett@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-6681-8054")),
Expand Down
25 changes: 20 additions & 5 deletions R/pr_relabel.R
Expand Up @@ -3,14 +3,16 @@
#'
#' @param s A string for reformatting
#' @param style The style of plotting the string will be used for
#' @param named Should the output be an `unnamed` (FALSE) or `named` (TRUE) vector? Only available for `style = "simple"` and `style = "plotly"`
#'
#'
#' @return A reformatted expression call (ggplot)
#' @export
#'
#' @examples
#' pr_relabel("Chla_mgm3", style = "ggplot")
#'
pr_relabel <- function(s, style = "ggplot"){
pr_relabel <- function(s, style = "ggplot", named = FALSE){

relabel_df <- tibble::as_tibble(matrix(c(
"AbundancePhyto_CellsL", rlang::expr(paste("Phytoplankton Abundance (cells L"^-1,")")), "Phytoplankton Abundance (cells L<sup>-1</sup>)", "Phytoplankton Abundance",
Expand Down Expand Up @@ -265,11 +267,24 @@ pr_relabel <- function(s, style = "ggplot"){
if(style == "ggplot" & length(i) > 0) {
return(relabel_df$gg[[i]]) # Returned as a list due to expr
} else if (style == "plotly" & length(i) > 0){
return(unlist(relabel_df$pl[i]))

if (isFALSE(named)) { # Unnamed vector
out <- unlist(relabel_df$pl[i])
} else { # Named vector
out <- relabel_df$Variable[i]
names(out) <- unlist(relabel_df$pl[i])
}
return(out)

} else if (style == "simple" & length(i) > 0){
out <- relabel_df$Variable[i]
names(out) <- relabel_df$simple[i]
out <- out[order(names(out))] # Put in alpha order

if (isFALSE(named)){ # Unnamed vector
out <- relabel_df$simple[i]
} else { # Named vector
out <- relabel_df$Variable[i]
names(out) <- relabel_df$simple[i]
out <- out[order(names(out))] # Put in alpha order
}
return(out)
} else if (length(i) == 1){
return(s) # If no match, return the original string
Expand Down
2 changes: 1 addition & 1 deletion R/pr_rename.R
Expand Up @@ -61,7 +61,7 @@ pr_rename <- function(df){
"TripCode", "TRIP_CODE",
"WoRMS AphiaID", "SPCODE",
"ZSampleDepth_m", "ZOOPSAMPLEDEPTH_M"),
ncol = 2, byrow = TRUE, dimnames = list(NULL, c("New","Old"))))
ncol = 2, byrow = TRUE, dimnames = list(NULL, c("New", "Old"))))

df <- data.table::setnames(df, old = rename_df$Old, new = rename_df$New, skip_absent = TRUE)

Expand Down
13 changes: 7 additions & 6 deletions R/utils_boo_plot.R
Expand Up @@ -542,11 +542,12 @@ pr_plot_tsfg <- function(df, Scale = "Actual", Trend = "Raw"){
#' @export
#'
#' @examples
#' df <- pr_get_EOVs("CPR") %>% pr_remove_outliers(2) %>%
#' df <- pr_get_EOVs("CPR") %>%
#' pr_remove_outliers(2) %>%
#' pr_get_Coeffs()
#' pr_plot_EOVs(df, EOV = "chl_oc3", Survey = "CPR",
#' trans = "identity", col = "blue", labels = "no")
pr_plot_EOVs <- function(df, EOV = "Biomass_mgm3", Survey = "NRS", trans = "identity", col = "blue", labels = "yes") {
#' trans = "identity", col = "blue", labels = FALSE)
pr_plot_EOVs <- function(df, EOV = "Biomass_mgm3", Survey = "NRS", trans = "identity", col = "blue", labels = TRUE) {

titley <- pr_relabel(EOV, style = "ggplot")

Expand All @@ -571,7 +572,7 @@ pr_plot_EOVs <- function(df, EOV = "Biomass_mgm3", Survey = "NRS", trans = "iden
#plot.subtitle = ggplot2::element_text(size = 12)
)

if(labels == "no"){
if(isFALSE(labels)){
p1 <- p1 +
ggplot2::theme(axis.title.x = ggplot2::element_blank())
}
Expand All @@ -588,7 +589,7 @@ pr_plot_EOVs <- function(df, EOV = "Biomass_mgm3", Survey = "NRS", trans = "iden
ggplot2::labs(y = "Anomaly") +
theme_pr()

if(labels == "no"){
if(isFALSE(labels)){
p2 <- p2 + ggplot2::theme(axis.title.x = ggplot2::element_blank())
}
if(Survey == "LTM"){
Expand All @@ -611,7 +612,7 @@ pr_plot_EOVs <- function(df, EOV = "Biomass_mgm3", Survey = "NRS", trans = "iden
ggplot2::theme(legend.position = "none",
axis.title.y = ggplot2::element_blank())

if(labels == "no"){
if(isFALSE(labels)){
p3 <- p3 +
ggplot2::theme(axis.title.x = ggplot2::element_blank())
}
Expand Down
7 changes: 4 additions & 3 deletions man/pr_plot_EOVs.Rd

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

4 changes: 3 additions & 1 deletion man/pr_relabel.Rd

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

0 comments on commit 7eac3e6

Please sign in to comment.