Axis guides: guide_axis
Mix.install([
{:giggly, path: Path.join(__DIR__, "..")},
{:kino, "~> 0.19"}
])
About this notebook
This notebook follows the examples on ggplot2's reference page for
guide_axis(), in the order the page
gives them. Each example shows ggplot2's code first and then Giggly's. An example Giggly cannot
draw yet keeps its ggplot2 code and names what it is waiting for, so the page is also a list of
what remains.
An axis is the guide that draws a position scale, such as the x or y scale, as ticks, labels and a
title. guide_axis() changes how one is drawn: it can spread crowded labels over several rows, turn
them to an angle or drop those that overlap, add minor ticks, and cut the axis line back to the
outermost breaks. It is given to a scale's guide argument or to guides(). Giggly has no axis
guides yet (guide_axis()); Giggly.Plot.theme/2 styles an axis's line, ticks and labels, and
turns its labels with angle:.
Dodging and turning labels
The example multiplies cty and hwy by 100 so that, in the narrow panels, the x axis's labels
are long enough to overlap.
# plot with overlapping text
p <- ggplot(mpg, aes(cty * 100, hwy * 100)) +
geom_point() +
facet_wrap(vars(class))
# axis guides can be customized in the scale_* functions or
# using guides()
p + scale_x_continuous(guide = guide_axis(n.dodge = 2))
p + guides(x = guide_axis(angle = 90))
Not in Giggly yet: guide_axis(), here to spread the x axis's labels over two rows or turn them
through 90 degrees.
A duplicate axis
# can also be used to add a duplicate guide
p + guides(x = guide_axis(n.dodge = 2), y.sec = guide_axis())
Not in Giggly yet: guide_axis() and secondary axes, here y.sec, a copy of the y axis on the
right.