Axis guide with capped axis line
guide_axis_cap.Rd
This is very similar to a regular axis guide, with the addition that the axis line can be capped By default, the axis line is capped at the most extreme breaks, but other options are available.
Arguments
- cap_lower, cap_upper
A way to set the lower and upper ranges for axis capping Can be one of the following:
NULL
to not perform any axis capping.A
function
that takes the break positions as input and returns the lower or upper boundary. Note that also for discrete scales, the inputs are the mapped breaks, which arenumeric
. Afunction
input can also be given as lambda syntax.A
numeric
value, in data units, for the lower and upper boundaries.A
<unit>
object to set the boundaries independent of any data.
- ...
Arguments passed on to
guide_axis_extend
subtitle
A
character()
orexpression()
giving a subtitle for the guide. IfNULL
(default), no subtitle will be shown. Iflength(subtitle) > 1
, text will be distributed over axis andhjust
setting will be ignored.subtitle.theme
An
<element_text>
object or<element_blank>
object controlling the appearance of thesubtitle
argument. By default, it inherits from the relevantaxis.text.{x/y}.{position}
theme setting.colour,color
A
character(1)
with a valid colour for simultaneously changing the colour or the axis text, axis ticks and axis line. IfNULL
(default), inherit colours directly from the theme. Otherwise, theme settings are overruled.minor_size
A
numeric(1)
giving the relative size of minor axis ticks relative to major axis ticks, as defined by theaxis.ticks.length.{x/y}.{position}
theme element. IfNULL
(default), minor axis ticks are not shown.major_size
A
numeric(1)
giving the relative size of major ticks relative to theaxis.ticks.length.{x/y}.{position}
theme element. IfNULL
(default), major ticks are drawn to the theme's length.title
A character string or expression indicating a title of guide. If
NULL
, the title is not shown. By default (waiver()
), the name of the scale object or the name specified inlabs()
is used for the title.check.overlap
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels.
angle
Compared to setting the angle in
theme()
/element_text()
, this also uses some heuristics to automatically pick thehjust
andvjust
that you probably want.n.dodge
The number of rows (for vertical axes) or columns (for horizontal axes) that should be used to render the labels. This is useful for displaying labels that would otherwise overlap.
order
A positive
integer
of length 1 that specifies the order of this guide among multiple guides. This controls in which order guides are merged if there are multiple guides for the same position. If 0 (default), the order is determined by a secret algorithm.position
Where this guide should be drawn: one of top, bottom, left, or right.
Value
A <Guide>
ggproto object that can be given to the
guides()
function, or set as the guide
argument
in a position scale.
See also
Other axis variants:
guide_axis_extend()
,
guide_axis_minor()
,
guide_axis_nested()
,
guide_axis_table()
Examples
# A basic plot with axis lines
p <- ggplot(mpg, aes(displ, hwy)) +
geom_point() +
theme(axis.line = element_line())
# By default, axis lines are truncated to extreme breaks
p + guides(x = "axis_cap")
# Turn off truncation at only one end
p + guides(x = guide_axis_cap(cap_upper = NULL))
# Truncated at specific data values
p + guides(x = guide_axis_cap(cap_lower = 3, cap_upper = 6))
# Truncated at some distance
p + guides(x = guide_axis_cap(
cap_lower = unit(3, "cm"),
cap_upper = unit(1, "npc") - unit(3, "cm")
))
# Truncation with functions take existing breaks as input
p + guides(x = guide_axis_cap(
cap_lower = function(x) x - 0.3,
cap_upper = ~ .x + 0.3 # rlang lambda syntax function
))