Skip to content
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

change segment grob to curve #131

Merged
merged 3 commits into from Apr 28, 2019
Merged

change segment grob to curve #131

merged 3 commits into from Apr 28, 2019

Conversation

malcolmbarrett
Copy link
Contributor

I was recently inspired by the annotation in the BBC R cookbook, which uses a curved line. It occured to me that this would be relatively easy to implement in ggrepel by changing segmentsGrob() to curveGrob() with the curvature set to 0 by default. This PR implements that change, adding the arguments segment.curvature, segment.angle, and segment.ncp to both repel geoms.

The default behavior remains the same.

library(ggrepel)
library(dplyr)

set.seed(3233)

p <- mtcars %>% 
  dplyr::mutate(lbls = rownames(mtcars)) %>% 
  ggplot(aes(wt, mpg, label = lbls, colour = factor(cyl))) +
  geom_point()

p + geom_text_repel()

But now you can add a curve (and control the details, as in geom_curve())

p + geom_text_repel(
  data = function(x) dplyr::sample_n(x, 3),
  nudge_y = 2,
  nudge_x = 1,
  segment.curvature = -.3,
  segment.angle = 80,
  segment.ncp = 3
)

p + geom_label_repel(
  data = function(x) dplyr::sample_n(x, 3),
  nudge_y = 2,
  nudge_x = 1, 
  segment.curvature = .5, 
  segment.ncp = 6,
)

Plus, you can do some fun annotation stuff with it.

p + geom_text_repel(
  data = function(x) dplyr::sample_n(x, 3),
  nudge_y = 1,
  nudge_x = 1,
  point.padding = .3,
  segment.curvature = -1e-20,
  segment.angle = 10,
  arrow = arrow(length = unit(0.02, "npc"), type = "closed")
)

Created on 2019-03-05 by the reprex package (v0.2.1)

@slowkow
Copy link
Owner

slowkow commented Mar 6, 2019

This looks awesome!

Thank you so much for the contribution. I look forward to merging.

Would you consider making a new example for the vignette that highlights this new feature?

@malcolmbarrett
Copy link
Contributor Author

Yes, happy to! I'll try to add one tomorrow

@malcolmbarrett
Copy link
Contributor Author

I updated the news and added an example. I didn't rebuild the vignette because I had some trouble with the makefile 😇

@malcolmbarrett
Copy link
Contributor Author

That Travis error on R-devel doesn't seem to have to do with the commit. The others built fine, and I rebuilt it on my copy of the repo, and all three worked 🤷‍♂️

@slowkow
Copy link
Owner

slowkow commented Mar 8, 2019

My best guess is that the failure is due to a network issue on the Travis CI servers.

I see:

* checking for future file timestamps ...Warning in file(con, "r") :
  cannot open URL 'http://worldclockapi.com/api/json/utc/now': HTTP status was '403 Forbidden'
 WARNING
unable to verify current time

To me, that means that Travis tried to get the current time from a 3rd party and failed.

I didn't know that checking a package would look for future time stamps! Pretty cool, I guess, if you trust data served by worldclockapi.com.

@malcolmbarrett
Copy link
Contributor Author

ha, I've had Travis time out on me before, but that's a new one! Anyway, let me know if you need me to do anything else before merging 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants