-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Make graticule labeling configurable #2849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ee2efae
to
e7d05ea
Compare
R/sf.R
Outdated
#' which side of the plot. Meridians are indicated by `"E"` (for East) and | ||
#' parallels by `"N"` (for North). Default is `"--EN"`, which specifies | ||
#' (clockwise from the top) no labels on the top, none on the right, meridians | ||
#' on the bottom, and paralleles on the left. Alternatively, this setting could have been |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paralleles -> parallels? (I'm assuming that's a typo not a map term I'm unfamiliar with)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo.
R/sf.R
Outdated
if (is.character(label_axes)) { | ||
label_axes <- parse_axes_labeling(label_axes) | ||
} else if (!is.list(label_axes)) { | ||
warning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather make this an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
R/sf.R
Outdated
if (is.character(label_graticules)) { | ||
label_graticules <- unlist(strsplit(label_graticules, "")) | ||
} else { | ||
warning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
R/sf.R
Outdated
#' their west end, whereas `label_graticules = "EW"` would label parallels at both | ||
#' ends and meridians not at all. Because meridians and parallels can in general | ||
#' intersect with any side of the plot panel, for any choice of `label_graticules` labels | ||
#' are not guaranteed to reside on only one particular side of the plot panel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include an example? Or maybe it's time to start a sf vignette? (Which would be a separate issue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a separate issue. Currently, all the sf documentation is combined into one .Rd file, and I think we're accumulating too much material to document everything carefully in this way. My proposal would be to start breaking things up, e.g. make a separate .Rd file just for coord_sf()
. There it would make sense to give more specific examples of how coord_sf()
works.
(As an aside, I would also like to consider breaking up the file sf.R
into coord-sf.R
, geom-sf.R
, stat-sf.R
, etc.)
@batpigandme can you please do a proof reading pass over the docs? |
470fb23
to
6a5dbd0
Compare
Before I merge this, I wanted to have one more quick discussion about the API. I have added two new parameters to library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3
library(ggplot2)
nc <- st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE)
# default
ggplot() + geom_sf(aes(fill = AREA), data=nc) + coord_sf() # default with rotated coordinate system
ggplot() + geom_sf(aes(fill = AREA), data=nc) + coord_sf(crs = 3338) # NSEW specification
ggplot() + geom_sf(aes(fill = AREA), data=nc) +
coord_sf(label_graticule = "NE") # axis labeling specification
ggplot() + geom_sf(aes(fill = AREA), data=nc) +
coord_sf(label_axes = list(top = "E", left = "N")) # combining both specifications, rotated coordinate system
ggplot() + geom_sf(aes(fill = AREA), data=nc) +
coord_sf(
crs = 3338,
label_graticule = "N",
label_axes = "-NE-"
) Created on 2018-09-14 by the reprex package (v0.2.0). I'm not fully happy with the parameter names. I think @hadley @batpigandme Any opinion on the naming? Any alternative suggestions that would be better? |
I think a common prefix is better than a common suffix. I share your sense that the current names are suboptimal, but I can't think of any better. This definitely feels complex enough (but not unnecessarily so) that we're going to soon need a bigger vignette/article discussing how to label maps. |
NEWS.md
Outdated
@@ -6,6 +6,10 @@ | |||
|
|||
* `coord_sf()` now respects manual setting of axis tick labels (@clauswilke, | |||
#2857, #2881). | |||
|
|||
* `coord_sf()` now accepts two new parameters `label_graticule` and `label_axes` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I'm the worst, can we offset the params as appositives? "…two new parameters, label_graticule and
label_axes`,…"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
@@ -622,23 +746,85 @@ sf_rescale01_x <- function(x, range) { | |||
} | |||
|
|||
|
|||
#' @param crs Use this to select a specific CRS. If not specified, will | |||
#' use the CRS defined in the first layer. | |||
#' @param crs Use this to select a specific coordinate reference system (CRS). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Every time you spell out an intiialism, an angel gets its wings.
R/sf.R
Outdated
#' parallels by `"N"` (for North). Default is `"--EN"`, which specifies | ||
#' (clockwise from the top) no labels on the top, none on the right, meridians | ||
#' on the bottom, and parallels on the left. Alternatively, this setting could have been | ||
#' specified with `list(left = "N", bottom = "E")`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have the order be consistent here? (i.e. bottom = "E", left = "N")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
#' should be labeled on their east or west end points, respectively. Thus, | ||
#' `label_graticule = "SW"` would label meridians at their south end and parallels at | ||
#' their west end, whereas `label_graticule = "EW"` would label parallels at both | ||
#' ends and meridians not at all. Because meridians and parallels can in general |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to make sure I understand this last sentence correctly (and, if I don't, perhaps some clarification is in order). label_graticule
is oriented to the map, not to the plot panel. So, label_graticule = "SW"
, for example, is not guaranteed to be in the bottom left corner of the plot panel. Is that kinda right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you understand correctly. In my experience, the result from label_graticule
specifications can look unexpected for rotated coordinate systems, and it usually takes me a minute or so to verify that it's actually correct. See example.
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3
library(ggplot2)
nc <- st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE)
ggplot() + geom_sf(aes(fill = AREA), data=nc) +
coord_sf(crs = 3338, label_graticule = "SW")
Created on 2018-09-15 by the reprex package (v0.2.0).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Yeah, it makes sense, I just wanted to double check.
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
This PR makes graticule labeling configurable. This closes #2846.
Edit 9/14/2018: I've removed outdated examples. New examples are provided below.