scale_x_time | R Documentation |
scale_x_time
formats a ggplot graph x axis to have breaks that make
sense for the user-specified time units and adds a minor tick between the
labels. It optionally adds padding to the left and right sides of the x axis.
scale_x_time(
time_range = NA,
impose_limits = TRUE,
time_units = "hours",
x_axis_interval = NA,
pad_x_axis = TRUE
)
time_range |
time range to show for the graph. Options:
|
impose_limits |
TRUE (default) or FALSE to actually set the
limits listed in |
time_units |
the units of time in the graph. Options are "hours" (default), "minutes", "days", or "weeks". |
x_axis_interval |
optionally set the x-axis major tick-mark interval. Acceptable input: any number or leave as NA to accept default values, which are generally reasonable guesses as to aesthetically pleasing and time-relevant intervals. |
pad_x_axis |
optionally add a smidge of padding to the the x axis
(default is TRUE, which includes some generally reasonable padding). If
changed to FALSE, the y axis will be placed right at the beginning of your
time range and all data will end exactly at the end of the time
range specified. If you want a specific amount of x-axis padding,
set this to a number; the default is |
a ggplot2 graph scale for the x axis (replaces scale_x_continuous in a graph)
MyData <- data.frame(Time = 0:168,
Conc = rnorm(n = 169, mean = 100))
ggplot(MyData, aes(x = Time, y = Conc)) +
geom_point() + scale_x_time()
ggplot(MyData, aes(x = Time, y = Conc)) +
geom_point() + scale_x_time(time_range = c(24, 48))
# You don't have to name the column with your x-axis data "Time".
MyAltData <- data.frame(Mango = 0:24,
Conc = rnorm(n = 25, mean = 100))
ggplot(MyAltData, aes(x = Mango, y = Conc)) +
geom_point() + scale_x_time()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.