Colour steps: guide_coloursteps
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_coloursteps(), which
covers guide_colorsteps() too, 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.
guide_coloursteps(), or guide_colorsteps() spelled the American way, is the legend of a binned
colour or fill scale: a colour bar, as guide_colourbar() draws, but with each bin in one constant
colour rather than a gradient. It is the default guide for binned colour scales. Giggly has none of
it yet: it has no binned scales, and draws a continuous colour or fill with ggplot2's default
gradient and its colour bar.
The default for binned colours
R's expand.grid() makes a row for every combination of X1 and X2 from 1 to 10, and value
is their product.
df <- expand.grid(X1 = 1:10, X2 = 1:10)
df$value <- df$X1 * df$X2
p <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
# Coloursteps guide is the default for binned colour scales
p + scale_fill_binned()
Not in Giggly yet: geom_tile(), scale_fill_binned(), and guide_coloursteps().
Bins of equal size
# By default each bin in the guide is the same size irrespectively of how
# their sizes relate in data space
p + scale_fill_binned(breaks = c(10, 25, 50))
Not in Giggly yet: geom_tile(), scale_fill_binned(), here with breaks of its own, and
guide_coloursteps().
Bins in proportion
# This can be changed with the `even.steps` argument
p + scale_fill_binned(
breaks = c(10, 25, 50),
guide = guide_coloursteps(even.steps = FALSE)
)
Not in Giggly yet: geom_tile(), scale_fill_binned(), and guide_coloursteps() with its
even.steps option, which sizes each bin in the legend in proportion to its range in the data.
Showing the limits
# By default the limits is not shown, but this can be changed
p + scale_fill_binned(guide = guide_coloursteps(show.limits = TRUE))
# (can also be set in the scale)
p + scale_fill_binned(show.limits = TRUE)
Not in Giggly yet: geom_tile(), scale_fill_binned(), and guide_coloursteps(), with the
show.limits option of the guide or of the scale, which labels the ends of the scale too.