scale_level_binned() classes a continuous variable into the whole-number
levels drawn by geom_urban_disc(). scale_level_discrete() does the same
for a factor, in the order of its levels.
Usage
scale_level_binned(
name = ggplot2::waiver(),
...,
breaks = ggplot2::waiver(),
limits = NULL,
oob = scales::oob_censor,
guide = guide_urban()
)
scale_level_discrete(name = ggplot2::waiver(), ..., guide = "legend")Arguments
- name
The legend title.
- ...
Other arguments passed on to
ggplot2::binned_scale()orggplot2::discrete_scale().- breaks
For
scale_level_binned(), the class boundaries. Values above the last break form the highest level.- limits
The range of the scale. The default for
scale_level_binned(),NULL, starts the scale at the first break whenbreaksis numeric.- oob
What to do with values outside
limits. The default censors them.- guide
The legend type. The default for
scale_level_binned()isguide_urban(), which shows one key and one range label for each class.
Details
By default scale_level_binned() follows the Urban Atlas convention that
a cell below the lowest class has no symbol: values under the first break
are censored, and the layer drops them.
Two variables on one plate
A plot has one scale for each aesthetic, so two layers that class
different variables, such as density discs under income rings, need a
second level scale. Add ggnewscale::new_scale("level") between the
two layers, and give each layer its own scale_level_binned().
Examples
library(ggplot2)
cells <- expand.grid(x = 1:8, y = 1:6)
cells$people <- 4000 * exp(-((cells$x - 3)^2 + (cells$y - 3)^2) / 6)
ggplot(cells, aes(x, y, level = people)) +
geom_urban_disc() +
scale_level_binned(
name = "Residential population density",
breaks = c(50, 200, 500, 1200, 3600)
) +
coord_equal()