Skip to content

Commit effa636

Browse files
committed
Merge branch 'master' of https://github.com/markpayneatwork/ggplot2 into markpayneatwork-master
2 parents 2105a02 + ae8937b commit effa636

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ version of ggplot.
337337
338338
## Bug fixes and minor improvements
339339
340+
* `borders()` now accepts xlim and ylim arguments for specifying the geographical
341+
region of interest (@markpayneatwork, #1392)
342+
340343
* All partially matched arguments and `$` have been been replaced with
341344
full matches (@jimhester, #1134).
342345

R/fortify-map.r

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ map_data <- function(map, region = ".", exact = FALSE, ...) {
7474
#' @param regions map region
7575
#' @param fill fill colour
7676
#' @param colour border colour
77+
#' @param xlim,ylim latitudinal and logitudinal range for extracting map polygons, see \code{\link[maps]{map}} for details
7778
#' @param ... other arguments passed onto \code{\link{geom_polygon}}
7879
#' @export
7980
#' @examples
@@ -92,10 +93,17 @@ map_data <- function(map, region = ".", exact = FALSE, ...) {
9293
#' borders("state") +
9394
#' geom_point(aes(size = pop)) +
9495
#' scale_size_area()
95-
#'
96+
#'
97+
#' #Same map, with geographical context
98+
#' data(us.cities)
99+
#' capitals <- subset(us.cities, capital == 2)
100+
#' ggplot(capitals, aes(long, lat)) +
101+
#' borders("world", xlim = c(-130, -60), ylim = c(20, 50)) +
102+
#' geom_point(aes(size = pop)) +
103+
#' scale_size_area() + coord_quickmap(xlim = c(-130, -60), ylim = c(20, 50))
96104
#' }
97-
borders <- function(database = "world", regions = ".", fill = NA, colour = "grey50", ...) {
98-
df <- map_data(database, regions)
105+
borders <- function(database = "world", regions = ".", fill = NA, colour = "grey50", xlim=NULL,ylim=NULL,...) {
106+
df <- map_data(database, regions, xlim = xlim, ylim = ylim)
99107
geom_polygon(aes_(~long, ~lat, group = ~group), data = df,
100108
fill = fill, colour = colour, ..., inherit.aes = FALSE)
101109
}

0 commit comments

Comments
 (0)