-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Added linejoin parameter to geom_segment. #2132
Conversation
R/geom-segment.r
Outdated
#' # Use lineend and linejoin to change the style of the segments | ||
#' df2 <- expand.grid(lineend = c('round', 'butt', 'square'), | ||
#' linejoin = c('round', 'mitre', 'bevel'), stringsAsFactors = FALSE) | ||
#' segments <- lapply(seq_len(nrow(df2)), function(i) { |
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.
This use of lapply()
will confuse most readers. Can you please generate with a simple helper function and copy and paste?
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've simplified this is to a single call to geom_segment, hope that helps.
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.
That's much better thanks.
Can you please take a hard look to see if you can simplify the plot still further? I suggested a couple of places to start.
R/geom-segment.r
Outdated
#' df2 <- expand.grid(lineend = c('round', 'butt', 'square'), | ||
#' linejoin = c('round', 'mitre', 'bevel'), stringsAsFactors = FALSE) | ||
#' df2 <- data.frame(df2, y = 1:9) | ||
#' ggplot() + |
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.
Can you please use house indenting rules? (http://style.tidyverse.org/syntax.html#long-lines)
R/geom-segment.r
Outdated
#' geom_segment(aes(x = 1, y = y, xend = 2, yend = y), df2, size = 4, | ||
#' lineend = df2$lineend, linejoin = df2$linejoin, | ||
#' arrow = arrow(length = unit(0.5, "inches"))) + | ||
#' geom_text(aes(x = 2, y = 1:9, label = paste(df2$lineend, df2$linejoin)), |
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 you can simplify this plot by setting data
and aes(y = y)
in the ggplot2 call. The geom_text()
layer shouldn't use df$
I've simplified to a single |
Looks good to me - thanks! |
@karawoo can you please merge by hand? |
Hello, any chance the linejoin option could also be added to geom_curve? Thank you, Oliver |
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 simply adds support for the
linejoin
parameter ofgrid::segmentsGrob
togeom_segment
, just like the existinglineend
parameter. This is especially useful when drawing large arrows that need to look sharp. The default of"round"
can look poor with filled arrows as all corners are rounded off.The default is the current fixed value.
I'm not sure about the appropriate sizes etc. for the added example as it depends a bit on the size that is drawn for the online docs.