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

Fixes #312 remove infinite values from plots #316

Merged
merged 1 commit into from
Jun 24, 2022
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
6 changes: 4 additions & 2 deletions R/plotconfiguration-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ XAxisConfiguration <- R6::R6Class(
trans = self$ggplotScale(),
breaks = self$prettyTicks(),
labels = self$prettyTickLabels(),
expand = self$ggplotExpansion()
expand = self$ggplotExpansion(),
oob = .removeInfiniteValues
Copy link
Member

@Yuri05 Yuri05 Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pchelle Is this OK without brackets?
oob = .removeInfiniteValues or
oob = .removeInfiniteValues() ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oob argument expects a function. So, oob = .removeInfiniteValues is good

Another way of doing this could be match.fun(".removeInfiniteValues ")

The default value is oob = censor, passing the function censor from the {scales} package.
However , the function does not remove Inf values by default.

Interestingly, all the arguments of scale_y_continous function handle function type values.
This was actually the approach for solving the ticks and tick labels of log scale plots

labels = self$prettyTickLabels() returns functions such as getLogTickLabels for log scale plots, but can also return getPiTickLabels if you are working with angles in radians or getGreekTickLabels if you want to use greek letters to name indices (these functions were refined in PR #304 and we could also envision a function for setting a calendar time format for tick labels)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting :)

)
)
# Add special tick lines for pretty log plots
Expand Down Expand Up @@ -344,7 +345,8 @@ YAxisConfiguration <- R6::R6Class(
trans = self$ggplotScale(),
breaks = self$prettyTicks(),
labels = self$prettyTickLabels(),
expand = self$ggplotExpansion()
expand = self$ggplotExpansion(),
oob = .removeInfiniteValues
)
)
# Add special tick lines for pretty log plots
Expand Down
11 changes: 11 additions & 0 deletions R/utilities-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,14 @@ getPiTickLabels <- function(ticks) {
piLabels[piLabels == ""] <- "0"
return(piLabels)
}

#' @title .removeInfiniteValues
#' @description Censor/remove any values outside of range
#' Caution, removing infinite values can cause issues with ribbons
#' which can use such infinite values for filling a range
#' @param x numeric vector of values to manipulate
#' @param range numeric vector of length two giving desired output range
#' @keywords internal
.removeInfiniteValues <- function(x, range = c(0,1)){
scales::censor(x, range, only.finite = FALSE)
}
17 changes: 17 additions & 0 deletions man/dot-removeInfiniteValues.Rd

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