Skip to content

Commit e21c4d6

Browse files
committed
document a bit
1 parent 281d36c commit e21c4d6

4 files changed

Lines changed: 87 additions & 1 deletion

File tree

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ Collate:
227227
'scale-date.R'
228228
'scale-discrete-.R'
229229
'scale-expansion.R'
230+
'scale-identity.R'
231+
'scale-geometry.R'
230232
'scale-gradient.R'
231233
'scale-grey.R'
232234
'scale-hue.R'
233-
'scale-identity.R'
234235
'scale-linetype.R'
235236
'scale-linewidth.R'
236237
'scale-manual.R'

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ export(scale_fill_stepsn)
614614
export(scale_fill_viridis_b)
615615
export(scale_fill_viridis_c)
616616
export(scale_fill_viridis_d)
617+
export(scale_geometry_discrete)
617618
export(scale_linetype)
618619
export(scale_linetype_binned)
619620
export(scale_linetype_continuous)

R/scale-geometry.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
#' Geometry scale
2+
#'
3+
#' The geometry scale is a translation scale, transforming feature identifiers
4+
#' into geometry using sf objects.
5+
#'
6+
#' @param data An sf object with a simple feature list (geometry) column.
7+
#' @param id A string giving a column name in `data` to use as feature identifiers.
8+
#' @param ... Passed on to [discrete_scale].
9+
#'
10+
#' @export
11+
#' @include scale-identity.R
12+
#'
13+
#' @examplesIf require("rnaturalearth")
14+
#' world <- rnaturalearth::ne_countries()
15+
#'
16+
#' # 1:1 mapping using three-letter country codes
17+
#' iso_a3 <- data.frame(id = c("AUS", "NZL", "PNG", "IDN"))
18+
#'
19+
#' ggplot(iso_a3) +
20+
#' geom_sf(aes(geometry = id, fill = id)) +
21+
#' scale_geometry_discrete(world, "iso_a3")
22+
#'
23+
#' # 1:many mapping using regions
24+
#' regions <- data.frame(id = c("Asia", "Europe"))
25+
#'
26+
#' ggplot(regions) +
27+
#' geom_sf(aes(geometry = id, fill = id)) +
28+
#' scale_geometry_discrete(world, "region_un")
29+
#'
30+
#' # Subnational identities
31+
#' states <- rnaturalearth::ne_states(country = "united states of america")
32+
#'
33+
#' west_us <- data.frame(id = c("WA", "OR", "CA"))
34+
#'
35+
#' ggplot(west_us) +
36+
#' geom_sf(aes(geometry = id, fill = id)) +
37+
#' scale_geometry_discrete(states, "postal")
138
scale_geometry_discrete <- function(data = NULL, id = NULL, ...) {
239
check_installed("sf")
340
transform <- new_geometry_transform(data, id)

man/scale_geometry_discrete.Rd

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)