scale_x_time_setup: Get the information needed to automatically scale a ggplot...

View source: R/scale_x_time_setup.R

scale_x_time_setupR Documentation

Get the information needed to automatically scale a ggplot graph x axis for time

Description

scale_x_time_setup gets the information needed from both user input and a user-supplied ggplot graph to format that ggplot graph x axis to have breaks that make sense for time. It uses breaks that are sensible for the time units supplied and adds a minor tick between the labels. It optionally adds padding to the left and right sides of the x axis. Well, it gets ready to do those things. To actually apply this, you'll need to use either scale_x_time or ggplot2::coord_cartesian with the output from scale_x_time_setup.

Usage

scale_x_time_setup(
  time_range = NA,
  time_units = "hours",
  x_axis_interval = NA,
  pad_x_axis = TRUE
)

Arguments

time_range

time range to show for the graph. Options:

NA

(default) entire time range of data

a start time and end time in hours

only include data in that range, e.g. time_range = c(24, 48). Note that there are no quotes around numeric data.

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 c(0.02, 0.04), which adds 2% more space to the left side and 4% more to the right side of the x axis. If you only specify one number, we'll assume that's the percent you want added to the left side.

Value

a list of information useful with scale_x_time or ggplot2::coord_cartesian

Examples

# None yet. Mainly for use inside SimcypConsultancy package.



shirewoman2/Consultancy documentation built on Feb. 18, 2025, 10 p.m.