Graded concentric-ring symbols on a regular lattice
Source:R/geom-urban-rings.R
geom_urban_rings.RdDraws the personal income symbol of the Urban Atlas: a ring of fixed diameter in every lattice cell, filled in by further concentric rings as the class of the cell rises, and then by a solid disc that grows until only the outer ring remains around it. The default has seven levels.
Usage
geom_urban_rings(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
pitch = NULL,
rings = urban_ring_steps$rings,
discs = urban_ring_steps$discs,
ring = 0.88,
stroke = 0.09,
inner_stroke = 0.065,
overprint = FALSE,
na.rm = TRUE,
show.legend = NA,
inherit.aes = TRUE
)Arguments
- mapping
Set of aesthetic mappings created by
aes(). If specified andinherit.aes = TRUE(the default), it is combined with the default mapping at the top level of the plot. You must supplymappingif there is no plot mapping.- data
The data to be displayed in this layer. There are three options:
If
NULL, the default, the data is inherited from the plot data as specified in the call toggplot().A
data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. Seefortify()for which variables will be created.A
functionwill be called with a single argument, the plot data. The return value must be adata.frame, and will be used as the layer data. Afunctioncan be created from aformula(e.g.~ head(.x, 10)).- stat
The statistical transformation to use on the data for this layer. When using a
geom_*()function to construct a layer, thestatargument can be used to override the default coupling between geoms and stats. Thestatargument accepts the following:A
Statggproto subclass, for exampleStatCount.A string naming the stat. To give the stat as a string, strip the function name of the
stat_prefix. For example, to usestat_count(), give the stat as"count".For more information and other ways to specify the stat, see the layer stat documentation.
- position
A position adjustment to use on the data for this layer. This can be used in various ways, including to prevent overplotting and improving the display. The
positionargument accepts the following:The result of calling a position function, such as
position_jitter(). This method allows for passing extra arguments to the position.A string naming the position adjustment. To give the position as a string, strip the function name of the
position_prefix. For example, to useposition_jitter(), give the position as"jitter".For more information and other ways to specify the position, see the layer position documentation.
- ...
Other arguments passed on to
layer()'sparamsargument. These arguments broadly fall into one of 4 categories below. Notably, further arguments to thepositionargument, or aesthetics that are required can not be passed through.... Unknown arguments that are not part of the 4 categories below are ignored.Static aesthetics that are not mapped to a scale, but are at a fixed value and apply to the layer as a whole. For example,
colour = "red"orlinewidth = 3. The geom's documentation has an Aesthetics section that lists the available options. The 'required' aesthetics cannot be passed on to theparams. Please note that while passing unmapped aesthetics as vectors is technically possible, the order and required length is not guaranteed to be parallel to the input data.When constructing a layer using a
stat_*()function, the...argument can be used to pass on parameters to thegeompart of the layer. An example of this isstat_density(geom = "area", outline.type = "both"). The geom's documentation lists which parameters it can accept.Inversely, when constructing a layer using a
geom_*()function, the...argument can be used to pass on parameters to thestatpart of the layer. An example of this isgeom_area(stat = "density", adjust = 0.5). The stat's documentation lists which parameters it can accept.The
key_glyphargument oflayer()may also be passed on through.... This can be one of the functions described as key glyphs, to change the display of the layer in the legend.
- pitch
The distance between neighbouring cell centres, in data units: one number, or two for a lattice spaced differently along
xandy. The default,NULL, uses the smallest gap between distinct values on each axis.- rings
A list with one element per level: the radii of the inner rings of that level, as fractions of half the pitch. Use
numeric()for a level without inner rings.- discs
The radius of the central disc for each level, as a fraction of half the pitch. Use
0for a level without a disc.- ring, stroke
Radius and line width of the outer ring, as fractions of half the pitch.
- inner_stroke
Line width of the inner rings, as a fraction of half the pitch.
- overprint
If
TRUE, the layer is printed over what lies beneath it as a second ink would be: overlapping inks darken (the multiply blend mode). Two saturated inks multiply to a colour close to black. For a different mix, give the name of another blend mode:"darken","overlay","soft.light","hard.light","color.burn","exclusion", or"difference". The plot must usecoord_urban(), which composes the layers. The graphics device must support compositing, as those of the ragg package andcairo_pdf()do.- na.rm
If
TRUE, the default, cells with a missinglevelare dropped silently. A cell below the lowest class has no symbol in the Urban Atlas, so missing levels are expected.- show.legend
logical. Should this layer be included in the legends?
NA, the default, includes if any aesthetics are mapped.FALSEnever includes, andTRUEalways includes. It can also be a named logical vector to finely select the aesthetics to display. To include legend keys for all levels, even when no data exists, useTRUE. IfNA, all levels are shown in legend, but unobserved levels are omitted.- inherit.aes
If
FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g.annotation_borders().
Aesthetics
geom_urban_rings() understands the following aesthetics. Required
aesthetics are in bold.
x,y: the cell centre.level: the class of the cell, a whole number from 1 tolength(discs). Map a continuous variable withscale_level_binned()or a factor withscale_level_discrete().colour: the ink. The default is the income ink of the"brick"palette. Seeurban_inks().alpha
See also
geom_urban_disc() for the density symbol, which this layer is
designed to be printed over.
Examples
library(ggplot2)
cells <- expand.grid(x = 1:8, y = 1:6)
cells$income <- 120 * exp(-((cells$x - 6)^2 + (cells$y - 4)^2) / 8)
ggplot(cells, aes(x, y, level = income)) +
geom_urban_rings() +
scale_level_binned(breaks = c(1, 5, 10, 20, 40, 60, 90)) +
coord_equal()