From 369427b46031c11d49decf10a7c0ca6ee274551d Mon Sep 17 00:00:00 2001 From: tdmcarthur Date: Wed, 24 Aug 2016 12:41:07 -0500 Subject: [PATCH 1/4] Added explicit 'parameters' argument to coord_map() in response to PR comment --- R/coord-map.r | 9 +++++---- man/coord_map.Rd | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/R/coord-map.r b/R/coord-map.r index 63e09fb1f9..c81c298009 100644 --- a/R/coord-map.r +++ b/R/coord-map.r @@ -21,7 +21,7 @@ #' @export #' @param projection projection to use, see #' \code{\link[mapproj]{mapproject}} for list -#' @param ... other arguments passed on to +#' @param parameters optional numeric vector of parameters for use with the projection argument. This argument is optional only in the sense that certain projections do not require additional parameters. Passed to #' \code{\link[mapproj]{mapproject}} #' @param orientation projection orientation, which defaults to #' \code{c(90, 0, mean(range(x)))}. This is not optimal for many @@ -46,7 +46,8 @@ #' #' # Other projections #' nzmap + coord_map("cylindrical") -#' nzmap + coord_map("azequalarea", orientation = c(-36.92,174.6,0)) +#' nzmap + coord_map("azequalarea", orientation = c(-36.92, 174.6, 0)) +#' nzmap + coord_map("lambert", parameters = c(-37, -44)) #' #' states <- map_data("state") #' usamap <- ggplot(states, aes(long, lat, group = group)) + @@ -83,12 +84,12 @@ #' # Centered on New York (currently has issues with closing polygons) #' worldmap + coord_map("ortho", orientation = c(41, -74, 0)) #' } -coord_map <- function(projection="mercator", ..., orientation = NULL, xlim = NULL, ylim = NULL) { +coord_map <- function(projection="mercator", parameters = NULL, orientation = NULL, xlim = NULL, ylim = NULL) { ggproto(NULL, CoordMap, projection = projection, orientation = orientation, limits = list(x = xlim, y = ylim), - params = list(...) + params = parameters ) } diff --git a/man/coord_map.Rd b/man/coord_map.Rd index 5758f2b9ba..4cc7b563a5 100644 --- a/man/coord_map.Rd +++ b/man/coord_map.Rd @@ -5,8 +5,8 @@ \alias{coord_quickmap} \title{Map projections.} \usage{ -coord_map(projection = "mercator", ..., orientation = NULL, xlim = NULL, - ylim = NULL) +coord_map(projection = "mercator", parameters = NULL, orientation = NULL, + xlim = NULL, ylim = NULL) coord_quickmap(xlim = NULL, ylim = NULL, expand = TRUE) } @@ -14,7 +14,7 @@ coord_quickmap(xlim = NULL, ylim = NULL, expand = TRUE) \item{projection}{projection to use, see \code{\link[mapproj]{mapproject}} for list} -\item{...}{other arguments passed on to +\item{parameters}{optional numeric vector of parameters for use with the projection argument. This argument is optional only in the sense that certain projections do not require additional parameters. Passed to \code{\link[mapproj]{mapproject}}} \item{orientation}{projection orientation, which defaults to @@ -65,7 +65,8 @@ nzmap + coord_quickmap() # Other projections nzmap + coord_map("cylindrical") -nzmap + coord_map("azequalarea", orientation = c(-36.92,174.6,0)) +nzmap + coord_map("azequalarea", orientation = c(-36.92, 174.6, 0)) +nzmap + coord_map("lambert", parameters = c(-37, -44)) states <- map_data("state") usamap <- ggplot(states, aes(long, lat, group = group)) + From c22a85bb4582beb165ab2053d3cd01f22913a00a Mon Sep 17 00:00:00 2001 From: tdmcarthur Date: Wed, 24 Aug 2016 14:52:24 -0500 Subject: [PATCH 2/4] Ensured that coord_map() fix is backward compatible --- NEWS.md | 3 +++ R/coord-map.r | 11 +++++++++-- man/coord_map.Rd | 6 ++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8a565497ab..bd8a9d0d81 100644 --- a/NEWS.md +++ b/NEWS.md @@ -200,6 +200,9 @@ * Fixed a compatibility issue with `ggproto` and R versions prior to 3.1.2. (#1444) +* Fixed issue where `coord_map()` fails when given an explicit `parameters` + argument (@tdmcarthur, #1729) + # ggplot2 2.0.0 ## Major changes diff --git a/R/coord-map.r b/R/coord-map.r index c81c298009..5d876f630a 100644 --- a/R/coord-map.r +++ b/R/coord-map.r @@ -21,6 +21,7 @@ #' @export #' @param projection projection to use, see #' \code{\link[mapproj]{mapproject}} for list +#' @param ... other arguments passed on to mapproject #' @param parameters optional numeric vector of parameters for use with the projection argument. This argument is optional only in the sense that certain projections do not require additional parameters. Passed to #' \code{\link[mapproj]{mapproject}} #' @param orientation projection orientation, which defaults to @@ -84,12 +85,18 @@ #' # Centered on New York (currently has issues with closing polygons) #' worldmap + coord_map("ortho", orientation = c(41, -74, 0)) #' } -coord_map <- function(projection="mercator", parameters = NULL, orientation = NULL, xlim = NULL, ylim = NULL) { +coord_map <- function(projection="mercator", ..., parameters = NULL, orientation = NULL, xlim = NULL, ylim = NULL) { + if (is.null(parameters)) { + params <- list(...) + } else { + params <- parameters + } + ggproto(NULL, CoordMap, projection = projection, orientation = orientation, limits = list(x = xlim, y = ylim), - params = parameters + params = params ) } diff --git a/man/coord_map.Rd b/man/coord_map.Rd index 4cc7b563a5..b2b2bfa389 100644 --- a/man/coord_map.Rd +++ b/man/coord_map.Rd @@ -5,8 +5,8 @@ \alias{coord_quickmap} \title{Map projections.} \usage{ -coord_map(projection = "mercator", parameters = NULL, orientation = NULL, - xlim = NULL, ylim = NULL) +coord_map(projection = "mercator", ..., parameters = NULL, + orientation = NULL, xlim = NULL, ylim = NULL) coord_quickmap(xlim = NULL, ylim = NULL, expand = TRUE) } @@ -14,6 +14,8 @@ coord_quickmap(xlim = NULL, ylim = NULL, expand = TRUE) \item{projection}{projection to use, see \code{\link[mapproj]{mapproject}} for list} +\item{...}{other arguments passed on to mapproject} + \item{parameters}{optional numeric vector of parameters for use with the projection argument. This argument is optional only in the sense that certain projections do not require additional parameters. Passed to \code{\link[mapproj]{mapproject}}} From fe855cfc33142c40f08a54bba77aad9730e4a36d Mon Sep 17 00:00:00 2001 From: tdmcarthur Date: Wed, 24 Aug 2016 15:20:03 -0500 Subject: [PATCH 3/4] Edited coord_map docs to say '...' ignored if 'parameters' arg exists --- R/coord-map.r | 2 +- man/coord_map.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/coord-map.r b/R/coord-map.r index 5d876f630a..1eb69927f5 100644 --- a/R/coord-map.r +++ b/R/coord-map.r @@ -21,7 +21,7 @@ #' @export #' @param projection projection to use, see #' \code{\link[mapproj]{mapproject}} for list -#' @param ... other arguments passed on to mapproject +#' @param ... other arguments passed on to mapproject. Ignored if the \code{parameters} argument is present. #' @param parameters optional numeric vector of parameters for use with the projection argument. This argument is optional only in the sense that certain projections do not require additional parameters. Passed to #' \code{\link[mapproj]{mapproject}} #' @param orientation projection orientation, which defaults to diff --git a/man/coord_map.Rd b/man/coord_map.Rd index b2b2bfa389..e3c70fb87a 100644 --- a/man/coord_map.Rd +++ b/man/coord_map.Rd @@ -14,7 +14,7 @@ coord_quickmap(xlim = NULL, ylim = NULL, expand = TRUE) \item{projection}{projection to use, see \code{\link[mapproj]{mapproject}} for list} -\item{...}{other arguments passed on to mapproject} +\item{...}{other arguments passed on to mapproject. Ignored if the \code{parameters} argument is present.} \item{parameters}{optional numeric vector of parameters for use with the projection argument. This argument is optional only in the sense that certain projections do not require additional parameters. Passed to \code{\link[mapproj]{mapproject}}} From 78464c1faa6c4482589f85fff1e1b60209141596 Mon Sep 17 00:00:00 2001 From: tdmcarthur Date: Tue, 6 Sep 2016 14:15:21 -0500 Subject: [PATCH 4/4] Added line breaks to coord_map() docs --- R/coord-map.r | 9 ++++++--- man/coord_map.Rd | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/coord-map.r b/R/coord-map.r index 1eb69927f5..c8870e4cc6 100644 --- a/R/coord-map.r +++ b/R/coord-map.r @@ -21,9 +21,12 @@ #' @export #' @param projection projection to use, see #' \code{\link[mapproj]{mapproject}} for list -#' @param ... other arguments passed on to mapproject. Ignored if the \code{parameters} argument is present. -#' @param parameters optional numeric vector of parameters for use with the projection argument. This argument is optional only in the sense that certain projections do not require additional parameters. Passed to -#' \code{\link[mapproj]{mapproject}} +#' @param ... other arguments passed on to \code{\link[mapproj]{mapproject}}. +#' Ignored if the \code{parameters} argument is present. +#' @param parameters optional numeric vector of parameters for use +#' with the projection argument. This argument is optional only in +#' the sense that certain projections do not require additional +#' parameters. Passed to \code{\link[mapproj]{mapproject}}. #' @param orientation projection orientation, which defaults to #' \code{c(90, 0, mean(range(x)))}. This is not optimal for many #' projections, so you will have to supply your own. See diff --git a/man/coord_map.Rd b/man/coord_map.Rd index e3c70fb87a..e386483497 100644 --- a/man/coord_map.Rd +++ b/man/coord_map.Rd @@ -14,10 +14,13 @@ coord_quickmap(xlim = NULL, ylim = NULL, expand = TRUE) \item{projection}{projection to use, see \code{\link[mapproj]{mapproject}} for list} -\item{...}{other arguments passed on to mapproject. Ignored if the \code{parameters} argument is present.} +\item{...}{other arguments passed on to \code{\link[mapproj]{mapproject}}. +Ignored if the \code{parameters} argument is present.} -\item{parameters}{optional numeric vector of parameters for use with the projection argument. This argument is optional only in the sense that certain projections do not require additional parameters. Passed to -\code{\link[mapproj]{mapproject}}} +\item{parameters}{optional numeric vector of parameters for use +with the projection argument. This argument is optional only in +the sense that certain projections do not require additional +parameters. Passed to \code{\link[mapproj]{mapproject}}.} \item{orientation}{projection orientation, which defaults to \code{c(90, 0, mean(range(x)))}. This is not optimal for many