-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#' Set up a time-based axis | ||
#' | ||
#' Set up a time-based axis for base graphics | ||
#' | ||
#' @param times A vector of date/times that will be plotted | ||
#' | ||
#' @param n Number of values to use in axis | ||
#' | ||
#' @return A data frame with the numeric values to plot plus labels to use. | ||
#' | ||
#' @export | ||
|
||
time_axis <- | ||
function(times, n=8) | ||
{ | ||
if(!("POSIXct" %in% class(times) || "POSIXt" %in% class(times))) { | ||
stop("times should be a vector of date/times") | ||
} | ||
|
||
prettyx <- pretty(times, n=n) | ||
|
||
r <- range(as.numeric(times)) | ||
dr <- diff(r) | ||
# determine range | ||
if(dr < 70) { # seconds | ||
labels <- format(prettyx, format="%S") | ||
} | ||
else if(dr < 60*70) { # minutes | ||
labels <- format(prettyx, format="%H:%M") | ||
} | ||
else if(dr < 60*60*26) { # hours | ||
labels <- format(prettyx, format="%H:%M") | ||
} | ||
else { # days | ||
labels <- format(prettyx, format="%Y-%m-%d") | ||
} | ||
|
||
# return vector of "pretty" times + labels | ||
data.frame(x=prettyx, label=labels) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.