Skip to content

Commit

Permalink
Documented functions, fixed check() warnings and fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Knicey committed Aug 22, 2024
1 parent 0a9fe65 commit d93434b
Show file tree
Hide file tree
Showing 11 changed files with 474 additions and 367 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Depends:
LazyData: true
VignetteBuilder: knitr
URL: https://knicey.github.io/stglyphs/
LazyDataCompression:xz
40 changes: 34 additions & 6 deletions R/geom_segment_glyph.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ GeomSegmentGlyph <- ggproto(
)
)

#' Rescale x-axis to 0,1
#' @param x The input array to be rescaled
#' @param xlim The limit of the rescaling. If NULL, the range of x is used.

#' @title rescale01x
#' @return A rescaled array based on the input array and provided limit that provides values between 0 and 1

#' @export
rescale01x <- function(x, xlim=NULL) {
Expand All @@ -90,14 +96,28 @@ rescale01x <- function(x, xlim=NULL) {
return(x)
}


#' Rescale x-axis to -1,1
#' @param x The input array to be rescaled
#' @param xlim The limit of the rescaling. If NULL, the range of x is used.

#' @title rescale11x
#' @return A rescaled array based on the input array and provided limit that provides values between -1 and 1

#' @export
rescale11x <- function(x, xlim=NULL) {
x = 2 * (rescale01x(x) - 0.5)
x = 2 * (rescale01x(x, xlim) - 0.5)
return(x)
}

#I need a special case for y because I have y and yend that need to be scaled
#the same way
#' Rescale y-axis to 0,1
#' This rescaling works differently to x rescaling because y and y end need to be rescaled together
#' @param y,yend The input arrays to be rescaled
#' @param ylim The limit of the rescaling. If NULL, the maximum value from y and yend is used.

#' @title rescale01y
#' @return A list of two rescaled arrays based on the input array and provided limit that provides values between 0 and 1

#' @export
rescale01y <- function(y, yend, ylim=NULL) {
if (is.null(ylim)) {
Expand All @@ -115,10 +135,18 @@ rescale01y <- function(y, yend, ylim=NULL) {
return(list(y, yend))
}

#' Rescale y-axis to -1,1
#' This rescaling works differently to x rescaling because y and y end need to be rescaled together
#' @param y,yend The input arrays to be rescaled
#' @param ylim The limit of the rescaling. If NULL, the maximum value from y and yend is used.
#'
#' @title rescale11y
#' @return A list of two rescaled arrays based on the input array and provided limit that provides values between -1 and 1
#'
#' @export
rescale11y <- function(y, yend, xlim=NULL) {
newy = 2 * (rescale01y(y, yend)[[1]] - 0.5)
newyend = 2 * (rescale01y(y, yend)[[2]] - 0.5)
rescale11y <- function(y, yend, ylim=NULL) {
newy = 2 * (rescale01y(y, yend, ylim)[[1]] - 0.5)
newyend = 2 * (rescale01y(y, yend, ylim)[[2]] - 0.5)

return(list(newy, newyend))
}
Expand Down
Binary file modified data/flights.rda
Binary file not shown.
19 changes: 19 additions & 0 deletions man/rescale01x.Rd

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

20 changes: 20 additions & 0 deletions man/rescale01y.Rd

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

19 changes: 19 additions & 0 deletions man/rescale11x.Rd

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

20 changes: 20 additions & 0 deletions man/rescale11y.Rd

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

Loading

0 comments on commit d93434b

Please sign in to comment.