Skip to content

Commit 0d9c298

Browse files
authored
Rename borders() to annotation_borders() (#6399)
* extract borders function * rename `borders()` -> `annotation_borders()` * propagate name change * deprecate `borders()` * document * remove unrelated example * adjust pkgdown index * use `annotate()` to avoid propagating labels * add test * add news bullet
1 parent f340b1a commit 0d9c298

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+176
-119
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Collate:
9393
'compat-plyr.R'
9494
'utilities.R'
9595
'aes.R'
96+
'annotation-borders.R'
9697
'utilities-checks.R'
9798
'legend-draw.R'
9899
'geom-.R'

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ export(after_scale)
297297
export(after_stat)
298298
export(alpha)
299299
export(annotate)
300+
export(annotation_borders)
300301
export(annotation_custom)
301302
export(annotation_logticks)
302303
export(annotation_map)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* `annotation_borders()` replaces the now-deprecated `borders()`
4+
(@teunbrand, #6392)
35
* New `make_constructor()` function that builds a standard constructor for
46
Geom and Stat classes (@teunbrand, #6142).
57
* In continuous scales, when `breaks` is a function and `n.breaks` is set, the

R/annotation-borders.R

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#' Create a layer of map borders
2+
#'
3+
#' This is a quick and dirty way to get map data (from the \pkg{maps} package)
4+
#' onto your plot. This is a good place to start if you need some crude
5+
#' reference lines, but you'll typically want something more sophisticated
6+
#' for communication graphics.
7+
#'
8+
#' @param database map data, see [maps::map()] for details
9+
#' @param regions map region
10+
#' @param fill fill colour
11+
#' @param colour border colour
12+
#' @param xlim,ylim latitudinal and longitudinal ranges for extracting map
13+
#' polygons, see [maps::map()] for details.
14+
#' @inheritDotParams geom_polygon
15+
#' @export
16+
#' @examples
17+
#' if (require("maps")) {
18+
#' data(us.cities)
19+
#' capitals <- subset(us.cities, capital == 2)
20+
#' ggplot(capitals, aes(long, lat)) +
21+
#' annotation_borders("state") +
22+
#' geom_point(aes(size = pop)) +
23+
#' scale_size_area() +
24+
#' coord_quickmap()
25+
#' }
26+
#'
27+
#' if (require("maps")) {
28+
#' # Same map, with some world context
29+
#' ggplot(capitals, aes(long, lat)) +
30+
#' annotation_borders("world", xlim = c(-130, -60), ylim = c(20, 50)) +
31+
#' geom_point(aes(size = pop)) +
32+
#' scale_size_area() +
33+
#' coord_quickmap()
34+
#' }
35+
annotation_borders <- function(database = "world", regions = ".", fill = NA,
36+
colour = "grey50", xlim = NULL, ylim = NULL, ...) {
37+
df <- map_data(database, regions, xlim = xlim, ylim = ylim)
38+
annotate(
39+
geom = "polygon",
40+
x = df$long, y = df$lat, group = df$group,
41+
fill = fill, colour = colour, ...
42+
)
43+
}
44+
45+
#' @export
46+
#' @rdname annotation_borders
47+
#' @usage borders(...) # Deprecated
48+
borders <- function(...) {
49+
deprecate_soft0("4.0.0", "borders()", "annotation_borders()")
50+
annotation_borders(...)
51+
}

R/fortify-map.R

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' plotted with ggplot2.
88
#'
99
#' @export
10-
#' @seealso [map_data()] and [borders()]
10+
#' @seealso [map_data()] and [annotation_borders()]
1111
#' @param model map object
1212
#' @param data not used by this method
1313
#' @param ... not used by this method
@@ -108,57 +108,3 @@ map_data <- function(map, region = ".", exact = FALSE, ...) {
108108
df[names(names)] <- vec_slice(names, df$group)
109109
vec_slice(df, stats::complete.cases(df$lat, df$long))
110110
}
111-
112-
#' Create a layer of map borders
113-
#'
114-
#' This is a quick and dirty way to get map data (from the \pkg{maps} package)
115-
#' onto your plot. This is a good place to start if you need some crude
116-
#' reference lines, but you'll typically want something more sophisticated
117-
#' for communication graphics.
118-
#'
119-
#' @param database map data, see [maps::map()] for details
120-
#' @param regions map region
121-
#' @param fill fill colour
122-
#' @param colour border colour
123-
#' @param xlim,ylim latitudinal and longitudinal ranges for extracting map
124-
#' polygons, see [maps::map()] for details.
125-
#' @inheritDotParams geom_polygon
126-
#' @export
127-
#' @examples
128-
#' if (require("maps")) {
129-
#'
130-
#' ia <- map_data("county", "iowa")
131-
#' mid_range <- function(x) mean(range(x))
132-
#' seats <- do.call(rbind, lapply(split(ia, ia$subregion), function(d) {
133-
#' data.frame(lat = mid_range(d$lat), long = mid_range(d$long), subregion = unique(d$subregion))
134-
#' }))
135-
#'
136-
#' ggplot(ia, aes(long, lat)) +
137-
#' geom_polygon(aes(group = group), fill = NA, colour = "grey60") +
138-
#' geom_text(aes(label = subregion), data = seats, size = 2, angle = 45)
139-
#' }
140-
#'
141-
#' if (require("maps")) {
142-
#' data(us.cities)
143-
#' capitals <- subset(us.cities, capital == 2)
144-
#' ggplot(capitals, aes(long, lat)) +
145-
#' borders("state") +
146-
#' geom_point(aes(size = pop)) +
147-
#' scale_size_area() +
148-
#' coord_quickmap()
149-
#' }
150-
#'
151-
#' if (require("maps")) {
152-
#' # Same map, with some world context
153-
#' ggplot(capitals, aes(long, lat)) +
154-
#' borders("world", xlim = c(-130, -60), ylim = c(20, 50)) +
155-
#' geom_point(aes(size = pop)) +
156-
#' scale_size_area() +
157-
#' coord_quickmap()
158-
#' }
159-
borders <- function(database = "world", regions = ".", fill = NA,
160-
colour = "grey50", xlim = NULL, ylim = NULL, ...) {
161-
df <- map_data(database, regions, xlim = xlim, ylim = ylim)
162-
geom_polygon(aes(.data$long, .data$lat, group = .data$group), data = df,
163-
fill = fill, colour = colour, ..., inherit.aes = FALSE)
164-
}

R/geom-segment.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ GeomSegment <- ggproto(
9898
#' ggplot(seals, aes(long, lat)) +
9999
#' geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat),
100100
#' arrow = arrow(length = unit(0.1,"cm"))) +
101-
#' borders("state")
101+
#' annotation_borders("state")
102102
#' }
103103
#'
104104
#' # Use lineend and linejoin to change the style of the segments

R/layer.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#' @param inherit.aes If `FALSE`, overrides the default aesthetics,
6565
#' rather than combining with them. This is most useful for helper functions
6666
#' that define both data and aesthetics and shouldn't inherit behaviour from
67-
#' the default plot specification, e.g. [borders()].
67+
#' the default plot specification, e.g. [annotation_borders()].
6868
#' @param check.aes,check.param If `TRUE`, the default, will check that
6969
#' supplied parameters and aesthetics are understood by the `geom` or
7070
#' `stat`. Use `FALSE` to suppress the checks.

_pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ reference:
9292
- annotation_logticks
9393
- annotation_map
9494
- annotation_raster
95-
- borders
95+
- annotation_borders
9696

9797
- title: Aesthetics
9898
desc: >

man/borders.Rd renamed to man/annotation_borders.Rd

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

man/fortify.map.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_bar.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_bin_2d.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_blank.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_boxplot.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_contour.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_count.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_density.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_density_2d.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_dotplot.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_function.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_hex.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_histogram.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_jitter.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_linerange.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_map.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_path.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_point.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)