This is a quick way to create a choropleth sketch of town-, neighborhood-, or tract-level data. Uses a corresponding sf
object; as of June 2018, this sf
object must be one that ships with this package, or otherwise be globally available.
Usage
quick_map(
data,
name = name,
value = value,
level = c("town", "neighborhood", "tract"),
city = NULL,
n = 5,
palette = "GnBu",
title = NULL,
...
)
Arguments
- data
A data frame containing data by geography.
- name
Bare column name of location names to join; defaults
name
.- value
Bare column name of numeric values to map; defaults
value
.- level
String giving the desired geographic level; must be one of
"town"
,"neighborhood"
, or"tract"
. Defaults"town"
.- city
If geographic level is neighborhood, string of the corresponding city name to match to a spatial object.
- n
Number of breaks into which to bin values; defaults (approximately) 5.
- palette
String of a ColorBrewer palette; see
RColorBrewer::RColorBrewer()
for possible values. Defaults"GnBu"
.- title
String giving the title, if desired, for the plot.
- ...
Arguments passed on to
ggplot2::geom_sf
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 supplymapping
if there is no plot mapping.stat
The statistical transformation to use on the data for this layer. When using a
geom_*()
function to construct a layer, thestat
argument can be used the override the default coupling between geoms and stats. Thestat
argument accepts the following:A
Stat
ggproto 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
position
argument 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.
na.rm
If
FALSE
, the default, missing values are removed with a warning. IfTRUE
, missing values are silently removed.show.legend
logical. Should this layer be included in the legends?
NA
, the default, includes if any aesthetics are mapped.FALSE
never includes, andTRUE
always includes.You can also set this to one of "polygon", "line", and "point" to override the default legend.
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.borders()
.
Examples
if (FALSE) { # \dontrun{
tidycensus::get_acs(
geography = "county subdivision",
variables = c(median_age = "B01002_001"), state = "09", county = "009"
) |>
town_names(NAME) |>
dplyr::filter(NAME %in% regions$`Greater New Haven`) |>
quick_map(name = NAME, value = estimate, title = "Median age by town, 2017", n = 6)
} # }