scale_datetime | R Documentation |
A date/time scale controls the mapping of date and time variables to visual properties.
scale_datetime(
vis,
property,
domain = NULL,
range = NULL,
reverse = NULL,
round = NULL,
utc = NULL,
clamp = NULL,
nice = NULL,
expand = NULL,
name = property,
label = NULL,
override = NULL
)
vis |
A ggvis object. |
property |
The name of a property, such as "x", "y", "fill", "stroke", etc. |
domain |
The domain of the scale, representing the set of data values.
For ordinal scales, a character vector; for quantitative scales, a numeric
vector of length two. Either value (but not both) may be NA, in which
case |
range |
The range of the scale, representing the set of visual values. For numeric values, the range can take the form of a two-element array with minimum and maximum values. For ordinal data, the range may by an array of desired output values, which are mapped to elements in the specified domain. The following range literals are also available: "width", "height", "shapes", "category10", "category20". |
reverse |
If true, flips the scale range. |
round |
If true, rounds numeric output values to integers. This can be helpful for snapping to the pixel grid. |
utc |
if |
clamp |
If |
nice |
If specified, modifies the scale domain to use a more human-friendly value range. Should be a string indicating the desired time interval; legal values are "second", "minute", "hour", "day", "week", "month", or "year". |
expand |
A multiplier for how much the scale should be expanded beyond
the domain of the data. For example, if the data goes from 10 to 110, and
|
name |
Name of the scale, such as "x", "y", "fill", etc. Can also be an arbitrary name like "foo". |
label |
Label for the scale. Used for axis or legend titles. |
override |
Should the domain specified by this ggvis_scale object
override other ggvis_scale objects for the same scale? Useful when domain is
manually specified. For example, by default, the domain of the scale
will contain the range of the data, but when this is TRUE, the specified
domain will override, and the domain can be smaller than the range of the
data. If |
scales
, scale_numeric
,
https://vega.github.io/vega/docs/scales/#time
Other scales:
scale_numeric()
,
scale_ordinal()
set.seed(2934)
dat <- data.frame(
time = as.Date("2013-07-01") + 1:100,
value = seq(1, 10, length.out = 100) + rnorm(100)
)
p <- dat %>% ggvis(~time, ~value) %>% layer_points()
# Start and end on month boundaries
p %>% scale_datetime("x", nice = "month")
dist <- data.frame(times = as.POSIXct("2013-07-01", tz = "GMT") +
rnorm(200) * 60 * 60 * 24 * 7)
p <- dist %>% ggvis(x = ~times) %>% layer_histograms()
p
# Start and end on month boundaries
p %>% scale_datetime("x", nice = "month")
p %>% scale_datetime("x", utc = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.