-
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.
Add function timeplot(), like grayplot() but with x-axis as date/time
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#' Scatterplot with date/times on the x-axis | ||
#' | ||
#' Like the [grayplot()] function, but with the x-axis having date/times | ||
#' | ||
#' @param x X-axis coordinates of points for the plot (must be date/time values) | ||
#' | ||
#' @param y Y-axis coordinates of points for the plot | ||
#' | ||
#' @param ... Optional graphics arguments passed to [grayplot()] | ||
#' | ||
#' @param n Approximate number of x-axis labels (passed to [base::pretty()]). | ||
#' | ||
#' @param scale Passed to [time_axis()] for defining the x-axis labels | ||
#' | ||
#' @param format Passed to [time_axis()] for defining the x-axis labels | ||
#' | ||
#' @return None. | ||
#' | ||
#' @export | ||
#' | ||
#' @importFrom graphics axis | ||
#' | ||
#' @examples | ||
#' n <- 100 | ||
#' y <- rnorm(n) | ||
#' x <- seq(as.POSIXct("2024-05-01 11:23"), as.POSIXct("2024-05-01 14:50"), length.out=n) | ||
#' timeplot(x, y) | ||
|
||
timeplot <- | ||
function(x, y, ..., n=5, scale=NULL, format=NULL) | ||
{ | ||
xax <- time_axis(x, n, scale, format) | ||
|
||
timeplot_internal <- | ||
function(x, y, vlines=NULL, mgp=c(2, 0.5, 0), mgp.x=NULL, mgp.y=NULL, ...) | ||
{ | ||
if(is.null(vlines)) vlines <- xax$x | ||
|
||
if(is.null(mgp.x)) mgp.x <- mgp | ||
if(is.null(mgp.y)) mgp.y <- mgp | ||
|
||
grayplot(x, y, xat=NA, vlines=vlines, mgp=mgp, mgp.x=mgp.x, mgp.y=mgp.y, ...) | ||
|
||
axis(side=1, at=xax$x, labels=xax$labels, tick=FALSE, mgp=mgp.x) | ||
} | ||
|
||
timeplot_internal(x, y, ...) | ||
invisible() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.