This axis guide is similar to the normal axis guides for position scales, but
can shorten the axis line that is being drawn. The
guide_axis_colour()
function is the same but with different defaults for the truncation that do
not truncate the axis. Axis truncation and recolouring is supported
throughout axes in ggh4x.
The function is deprecated as ggplot2::guide_axis(cap = TRUE)
has this
functionality now.
guide_axis_truncated(
title = waiver(),
check.overlap = FALSE,
angle = NULL,
n.dodge = 1,
order = 0,
colour = NULL,
color = NULL,
trunc_lower = min,
trunc_upper = max,
position = waiver()
)
guide_axis_colour(
title = waiver(),
check.overlap = FALSE,
angle = NULL,
n.dodge = 1,
order = 0,
colour = NULL,
color = NULL,
trunc_lower = NULL,
trunc_upper = NULL,
position = waiver()
)
guide_axis_color(
title = waiver(),
check.overlap = FALSE,
angle = NULL,
n.dodge = 1,
order = 0,
colour = NULL,
color = NULL,
trunc_lower = NULL,
trunc_upper = NULL,
position = waiver()
)
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 in labs()
is used for the title.
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels.
Compared to setting the angle in theme()
/ element_text()
,
this also uses some heuristics to automatically pick the hjust
and vjust
that
you probably want. Can be one of the following:
NULL
to take the angles and hjust
/vjust
directly from the theme.
waiver()
to allow reasonable defaults in special cases.
A number representing the text angle in degrees.
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.
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.
A character(1)
with a valid colour for colouring the
axis text, axis ticks and axis line. Overrules the colour assigned by the
theme.
The lower and upper range of the truncated axis:
NULL
to not perform any truncation.
A function
that takes the break positions as input and returns the lower
or upper boundary. Note that also for discrete scales, positions are the
mapped positions as numeric
.
A numeric
value in data units for the lower and upper boundaries.
A unit
object.
Where this guide should be drawn: one of top, bottom, left, or right.
An axis_ggh4x guide class object.
Other axis-guides:
guide_axis_logticks()
,
guide_axis_manual()
,
guide_axis_minor()
,
guide_axis_nested()
,
guide_axis_scalebar()
# Make a plot
p <- ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme(axis.line = element_line(colour = "black"))
# Setting the default truncated axis
p + guides(x = "axis_truncated")
#> Warning: `guide_axis_truncated()` was deprecated in ggh4x 0.3.0.
#> ℹ Please use `ggplot2::guide_axis(cap = TRUE)` instead.
#> ℹ The deprecated feature was likely used in the ggplot2 package.
#> Please report the issue at <https://github.com/tidyverse/ggplot2/issues>.
# Truncating in data units
p + guides(x = guide_axis_truncated(
trunc_lower = 2.5, trunc_upper = 4.5
))
# Truncate by setting units
p + guides(x = guide_axis_truncated(
trunc_lower = unit(0.1, "npc"),
trunc_upper = unit(0.9, "npc")
))
# Truncating with functions
p + guides(x = guide_axis_truncated(
trunc_lower = function(x) {x - 0.2},
trunc_upper = function(x) {x + 0.2}
))
# Recolouring the axes outside the theme
p + guides(x = guide_axis_colour(colour = "red"),
y = guide_axis_colour(colour = "blue"))