scale_x_spiral_axis() and scale_y_spiral_axis() are ordinary continuous
scales that additionally carry the settings of the axis which
coord_spiral() paints along the spiral: where the axis sits, how long its
ticks are and how its labels are turned.
Usage
scale_x_spiral_axis(
...,
discrete = FALSE,
axis_at = NULL,
tick_length = 0.007,
label_rot = NULL,
label_size = NULL,
show = TRUE
)
scale_y_spiral_axis(
...,
side = c("end", "start", "both"),
axis_at = NULL,
tick_length = 0.008,
label_rot = NULL,
label_size = NULL,
max_labels = NULL,
show = TRUE
)Arguments
- ...
Passed on to
ggplot2::scale_x_continuous()/ggplot2::scale_x_discrete()orggplot2::scale_y_continuous(), for examplebreaks,minor_breaks,labels,limitsortrans.minor_breaksdraws the short unlabelled ticks between two breaks; the coord paints them at 55% oftick_length, andminor_breaks = NULLleaves them out.- discrete
Use a discrete scale instead of a continuous one, for a factor or character x aesthetic (one violin or box per category). Only
scale_x_spiral_axis()needs it;breaksthen takes the category values.- axis_at
Put the radial (y) ruler at a fixed direction instead, in degrees measured counter-clockwise from the east (right) direction:
0is right,90top,180left. The last crossing of that direction on the outermost turn is used.NULLkeeps thesidebehaviour. Ignored byscale_x_spiral_axis(), whose axis runs at every break along the spiral.- tick_length
Length of the ticks, in npc units (the panel is 1 x 1). Use
0to hide the ticks. The coord shortens the ticks (and keeps the labels just outside them) so that both stay inside the white gap between two neighbouring turns, whateverheight/gapis.- label_rot
Rotation of the labels in degrees.
NULL(the default) turns every label along the spiral, so it follows the arc; a number turns all labels by that fixed angle, e.g.90for always-vertical labels.- label_size
Text size in points.
NULLinheritsaxis.text.x/axis.text.yfrom the theme.- show
Draw this axis at all?
FALSEhides the ticks and labels while keeping the data, which is handy for facets where the axis is redundant.- side
Where the radial (y) ruler is drawn: at the
"start"of the spiral, at its"end"(the default) or on"both"sides, exactly like thesideargument ofspiralize::spiral_yaxis(). Every tick is a short segment that runs along the spiral, and its label is turned to the tangent at that point, so it reads along the arc and never ends up upside down. Only used byscale_y_spiral_axis(); ignored whenaxis_atis given.- max_labels
Maximum number of radial labels kept when the track is too thin for all the breaks.
NULLkeeps every break. Only used byscale_y_spiral_axis().
Details
Use them exactly like ggplot2::scale_x_continuous() /
ggplot2::scale_y_continuous(); breaks, minor_breaks, labels,
limits, trans, ... keep their usual meaning, so the ticks shown on the
spiral are the breaks of the scale.
Both axes size themselves against the white gap between two turns: the ticks are shortened to fit, the labels sit just outside them, and the number of radial labels follows the thickness of the track and the height of the device. Nothing has to be tuned by hand, but every piece can still be overridden through the arguments below.
Examples
library(ggplot2)
d <- data.frame(x = seq(0, 1, length.out = 200),
y = sin(seq(0, 1, length.out = 200) * 6 * pi) * .35 + .5)
ggplot(d, aes(x, y)) +
geom_line() +
scale_x_spiral_axis(breaks = seq(0, 1, by = .1), label_size = 6) +
scale_y_spiral_axis(breaks = c(.3, .5, .7), axis_at = 0, label_rot = 90) +
coord_spiral()
