This function provides a convenient way to set default options for ref.x or
ref.y layers in openair plots, which show some form of horizontal or
vertical reference line or band. intercept can be a vector of any length
(for lines) or an even numbered vector representing pairs of bounds (for
bands); all other arguments besides label will be recycled to be the
correct length. Use method to change between lines and bands.
Usage
refOpts(
intercept,
alpha = 1,
colour = "black",
linetype = 1,
linewidth = 0.6,
label = NULL,
label_size = 10,
label_colour = NULL,
color = NULL,
label_color = NULL,
method = c("line", "band")
)Arguments
- intercept
The axis intercept(s) for the reference lines. Should be numeric, dates, or date-times depending on the axis types. If another data type is provided, it will attempt to be coerced to the correct type using
as.numeric(),lubridate::as_date()orlubridate::as_datetime(), respectively.- alpha
Numeric value between
0and1specifying the transparency of the lines. Default is1(fully opaque) for lines and0.1for bands.- colour, color
Colour of the lines and/or bands. Default is
"black".colourandcolorare interchangeable, butcolouris used preferentially if both are given.- linetype
Line type. Can be an integer (e.g.,
1for solid,2for dashed) or a string (e.g.,"solid","dashed"). Default is1(solid).- linewidth
Numeric value specifying the width of the lines. Default is
1for lines and0for bands.- label, label_size, label_colour, label_color
labeltakes character string to add a direct label to the reference line. Forref.xthis will be on the right hand side of the plot, and forref.ythis will be on top.label_sizeandlabel_colourset label aesthetics, with the latter defaulting tocolourif not set.- method
One of
"line"or"band". The former will create any number of horizontal or vertical reference lines atinterceptvalues. The latter will use pairs ofinterceptvalues to create any number of horizontal or vertical shaded areas/bands.
Value
A list of options that can be passed to the ref.x or ref.y
arguments of functions like timePlot().
Examples
# `ref.y` can just be a value to plot
timePlot(mydata, avg.time = "month", ref.y = 250, ref.x = "2002/01/01")
# use the `refOpts()` function to customise reference lines
timePlot(
mydata,
avg.time = "month",
ref.y = refOpts(
c(250, 300),
alpha = c(0.5, 1),
colour = c("grey50", "blue"),
linetype = c(2, 1),
linewidth = c(1, 2)
)
)
# use the 'bands' method for shaded areas
timePlot(
mydata,
avg.time = "month",
ref.y = refOpts(
c(200, 225, 250, 275),
colour = c("purple", "green"),
method = "band"
)
)
