Skip to content

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

Merged
merged 13 commits into from
Sep 15, 2018

Conversation

clauswilke
Copy link
Member

@clauswilke clauswilke commented Aug 23, 2018

This PR makes graticule labeling configurable. This closes #2846.

Edit 9/14/2018: I've removed outdated examples. New examples are provided below.

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
Copy link
Member

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)

Copy link
Member Author

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(
Copy link
Member

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

Copy link
Member Author

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error too

Copy link
Member Author

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.
Copy link
Member

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)

Copy link
Member Author

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.)

@hadley hadley requested a review from batpigandme September 12, 2018 20:02
@hadley
Copy link
Member

hadley commented Sep 12, 2018

@batpigandme can you please do a proof reading pass over the docs?

@clauswilke clauswilke mentioned this pull request Sep 12, 2018
25 tasks
@clauswilke
Copy link
Member Author

Before I merge this, I wanted to have one more quick discussion about the API. I have added two new parameters to coord_sf(), label_graticule and label_axes. I'll provide some examples of how they work and then bring up a few points about the parameter names.

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 graticule_labeling and axis_labeling may be preferably. The downside of that naming is that then the two parameters don't start with the same word. Since they do very similar things, having the parameters start with the same name is useful.

@hadley @batpigandme Any opinion on the naming? Any alternative suggestions that would be better?

@hadley
Copy link
Member

hadley commented Sep 14, 2018

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`
Copy link
Contributor

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`,…"

Copy link
Member Author

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).
Copy link
Contributor

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")`.
Copy link
Contributor

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")

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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).

Copy link
Contributor

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.

@clauswilke clauswilke merged commit 484a220 into tidyverse:master Sep 15, 2018
@clauswilke clauswilke deleted the issue-2846-coord_sf branch September 15, 2018 16:14
@lock
Copy link

lock bot commented Mar 14, 2019

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/

@lock lock bot locked and limited conversation to collaborators Mar 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

geom_sf() does not respect position argument of scale_y_continuous()
3 participants