# NOT RUN {
library(ggplot2)
# Using the `level` compute aesthetic from `geom_contour_fill()`
# (or ggplot2::geom_contour_filled()), the default scale is discrete.
# This means that you cannot map colours to the underying numbers.
v <- ggplot(faithfuld, aes(waiting, eruptions, z = density))
v + geom_contour_fill(aes(fill = stat(level)))
v + geom_contour_fill(aes(fill = stat(level))) +
scale_fill_discretised()
# The scale can be customised the same as any continuous colour scale
v + geom_contour_fill(aes(fill = stat(level))) +
scale_fill_discretised(low = "#a62100", high = "#fff394")
v + geom_contour_fill(aes(fill = stat(level))) +
scale_fill_divergent_discretised(midpoint = 0.02)
# Existing continous scales can be "retrofitted" by changing the `super`
# and `guide` arguments.
v + geom_contour_fill(aes(fill = stat(level))) +
scale_fill_distiller(super = ScaleDiscretised, guide = guide_colorsteps())
# Unequal breaks will, by default, map to unequal spacing in the guide
v + geom_contour_fill(aes(fill = stat(level)), breaks = c(0, 0.005, 0.01, 0.02, 0.04)) +
scale_fill_discretised()
# You can change that by the `even.steps` argument on ggplot2::guide_colorsteps()
v + geom_contour_fill(aes(fill = stat(level)), breaks = c(0, 0.005, 0.01, 0.02, 0.04)) +
scale_fill_discretised(guide = guide_colorsteps(even.steps = TRUE, show.limits = TRUE))
# }
Run the code above in your browser using DataLab