diff --git a/R/utils.R b/R/utils.R index 560d527..43ae0bd 100644 --- a/R/utils.R +++ b/R/utils.R @@ -441,15 +441,29 @@ trans_seq_rev<- function(unit = c("Mb", "kb", "bp")){ function(x) {paste(x, unit)} } -scale_x_sequnit <- function(unit = c("Mb", "kb", "bp"), append = NULL){ +scale_x_sequnit <- function(unit = c("Mb", "kb", "bp"), append = NULL, ...){ unit <- match.arg(unit) - if(is.null(append)){ - scale_x_continuous(breaks = trans_breaks(trans_seq(unit), - trans_seq_rev(unit)), - labels = trans_format(trans_seq_format(unit), math_format(.x))) - }else{ + check_args <- function() { + kwargs <- names(list(...)) + if (is.null(append)) { + if (any(c("breaks", "labels") %in% kwargs)) + stop("scale_x_sequnit already sets breaks and labels arguments when 'append' is set.") + } else { stopifnot(is.character(append)) - scale_x_continuous(labels = trans_format(.append_unit(append), math_format(.x))) + if ("labels" %in% names(list(...))) + stop("scale_x_sequnit already sets 'labels' argument.") + } + } + check_args() + if(is.null(append)){ + scale_x_continuous( + breaks = trans_breaks(trans_seq(unit), trans_seq_rev(unit)), + labels = trans_format(trans_seq_format(unit), math_format(.x)), + ...) + } else { + scale_x_continuous( + labels = trans_format(.append_unit(append), math_format(.x)), + ...) } } diff --git a/man/scale_x_sequnit.Rd b/man/scale_x_sequnit.Rd index 813c69f..878674e 100644 --- a/man/scale_x_sequnit.Rd +++ b/man/scale_x_sequnit.Rd @@ -5,17 +5,22 @@ scale x by unit 'Mb','kb', 'bp'. } \usage{ -scale_x_sequnit(unit = c("Mb", "kb", "bp"), append = NULL) +scale_x_sequnit(unit = c("Mb", "kb", "bp"), append = NULL, ...) } \arguments{ \item{unit}{ - unit to scale x. Default is Mb. + unit to scale x. Default is Mb. } \item{append}{ - default \code{NULL}. If pass a character, it disalbe unit and arbitrarily append a - text behind the original x scale numbers. + default \code{NULL}. If pass a character, it disable unit and arbitrarily append a + text behind the original x scale numbers. + } + \item{...}{ + arguments to pass to \code{scale_x_continuous}. + Note that \code{scale_x_sequnit} sets breaks and labels + automatically, so arguments \code{breaks} and \code{labels} cannot + be passed (\code{breaks} can if \code{append} is not set). } - } \value{ 'position_c' @@ -30,4 +35,4 @@ p + scale_x_sequnit("kb") p + scale_x_sequnit("bp") } \author{Tengfei Yin} - +\author{samuel barreto}