Skip to content

allow geom_sf to accept line parameters (#2826) #2847

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 11 commits into from
Aug 23, 2018
Merged

allow geom_sf to accept line parameters (#2826) #2847

merged 11 commits into from
Aug 23, 2018

Conversation

alistaire47
Copy link
Contributor

@alistaire47 alistaire47 commented Aug 22, 2018

This closes #2826, allowing lineend, linejoin, and linemitre arguments to be passed through geom_sf. I copied the defaults directly from geom_path, so this shouldn't alter the results of current code.

The only change I had to make beyond what Claus mentioned on the issue was assigning the parameters to coord so they get passed through to sf_grob. There may be a simpler way to structure that. If so, let me know and I'll refactor.

For now, I decided against adding them as explicit parameters to geom_sf, as while it would make sense for lines, it would sound like they'd apply to polygons, too, which they wouldn't, and thus may cause more confusion than it'd remove.

This builds and performs fine. I didn't add any tests, as the geom_sf tests don't currently test its line behavior, but can if you like. I do get an error when checking due to the economics_long dataset. I didn't touch it, but it gives me a C++ error when printed, even though str works fine:

> economics_long
Error: Not compatible with STRSXP: [type=list].

I suspect this means I've got a dependency issue with tibble or something, but I can't figure out what. I presume that if it has been working in CI builds, it will continue to do so.

Apologies for the extra commits in there; I realized too late that I didn't rebase fully. They shouldn't do anything at this point, so if there's some git-fu to clean them out, I'd be happy to remove them.

@clauswilke
Copy link
Member

Looks good to me. I have only one comment: Since sf_grob() is an internal function used only at that one point in the code, the lineend, linejoin, and linemitre could also simply be handed through as arguments to that function. Not sure whether there's a strong argument for or against that approach versus yours.

The extraneous git commits will disappear when we squash-merge, so don't worry about them.

@clauswilke
Copy link
Member

Sorry, one more comment: Could you add a news bullet to NEWS.md with a brief description and your github user name and issue number?

@alistaire47
Copy link
Contributor Author

Oh, I think that's better; those coord$lineend <- lineend lines feel like un-R-like boilerplate code.

The arguments will still get passed to sf_grob for point/multipoints, but ignored due to the logic therein, so it seems fine. I also noticed that the parameters get respected for polygons, which was unexpected but nice:

library(ggplot2)

ggplot(sf::st_polygon(list(matrix(c(0, 1, 2, 0, 0, 2, 1, 0), ncol = 2)))) + 
    geom_sf(size = 3, linejoin = 'mitre', fill = 'pink')

ggplot(sf::st_polygon(list(matrix(c(0, 1, 2, 0, 0, 2, 1, 0), ncol = 2)))) + 
    geom_sf(size = 3, linejoin = 'bevel', fill = 'lightgreen')

@alistaire47
Copy link
Contributor Author

Oops, forgot, sorry! Updated.

@clauswilke
Copy link
Member

Apologies for being picky. Would you mind adding a comma after linejoin in the news bullet. For context, see here: #2669 (comment)

@alistaire47
Copy link
Contributor Author

Hah, that's now the smallest commit I've ever made.

@clauswilke
Copy link
Member

@hadley Looks good to me.

@clauswilke clauswilke merged commit 74eb2b4 into tidyverse:master Aug 23, 2018
@lock
Copy link

lock bot commented Feb 19, 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 Feb 19, 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 pass parameters through to layer
3 participants