Description Usage Arguments Details Examples
Horizon chart of multiple time series
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
dates |
Vector of dates as character strings (e.g., as |
df |
Data frame with rows = dates, columns = values to plot |
date_format |
A character string representing the format of |
digits |
Number of digits to show when hovering. |
width |
width in pixels |
height |
height in pixels |
axis_height |
height of axis in pixels |
axis_ticks |
Number of ticks on axes |
padding |
Padding around figure |
colors |
A vector of character strings with RGB colors (like
|
tick_format |
A character string representing the format for date/times in the top and bottom axes.
See D3 v3 Time Formatting
for the specifier strings (such as |
focus_format |
A character string representing the format for date/time at the focus line.
See D3 v3 Time Formatting
for the specifier strings (such as |
The input dates
need to be converted from character strings to JSON dates.
The argument date_format
is used for this. It's a character string like
"%Y-%m-%d"
that is used to parse the dates. Here are some of the available
codes. (For a complete list, see
the d3.js documentation.)
%Y
- 4-digit year (e.g., 2016
)
%y
- 2-digit year (e.g., 16
)
%m
- 2-digit month
%d
- 2-digit day-of-month
%b
- Month as text (e.g., Mar
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # data included with package
file <- system.file("extdata", "test.csv", package="horizon")
x <- read.csv(file)
horizon(x[,1], x[,-1])
# second example with simulated data
n <- 600 # number of time points
p <- 26 # number of time series
# construct sequence of dates
dates <- as.character( seq( lubridate::ymd("1969-12-20"), by=7, length=n) )
# simulate brownian motion, all starting at 0
y <- matrix(0, nrow=n, ncol=p)
y[-1,] <- rnorm((n-1)*p, 0, 0.25)
y <- apply(y, 2, cumsum)
colnames(y) <- letters[1:p]
# make the horizon plot
horizon(dates, y)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.