-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Added linejoin parameter to geom_segment. #2132
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#' @inheritParams geom_point | ||
#' @param arrow specification for arrow heads, as created by arrow(). | ||
#' @param lineend Line end style (round, butt, square). | ||
#' @param linejoin Line join style (round, mitre, bevel). | ||
#' @seealso \code{\link{geom_path}} and \code{\link{geom_line}} for multi- | ||
#' segment lines and paths. | ||
#' @seealso \code{\link{geom_spoke}} for a segment parameterised by a location | ||
|
@@ -42,6 +43,19 @@ | |
#' arrow = arrow(length = unit(0.1,"cm"))) + | ||
#' borders("state") | ||
#' | ||
#' # 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) { | ||
#' annotate(geom = 'segment', x = 1, y = i, xend = 2, yend = i, size = 5, | ||
#' lineend = df2$lineend[i], linejoin = df2$linejoin[i], arrow = arrow(type = "closed")) | ||
#' }) | ||
#' ggplot() + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
#' segments + | ||
#' 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 commentThe reason will be displayed to describe this comment to others. Learn more. I think you can simplify this plot by setting |
||
#' hjust = 'outside', nudge_x = 0.2) + | ||
#' xlim(1, 2.25) | ||
#' | ||
#' # You can also use geom_segment to recreate plot(type = "h") : | ||
#' counts <- as.data.frame(table(x = rpois(100,5))) | ||
#' counts$x <- as.numeric(as.character(counts$x)) | ||
|
@@ -54,6 +68,7 @@ geom_segment <- function(mapping = NULL, data = NULL, | |
..., | ||
arrow = NULL, | ||
lineend = "butt", | ||
linejoin = "round", | ||
na.rm = FALSE, | ||
show.legend = NA, | ||
inherit.aes = TRUE) { | ||
|
@@ -68,6 +83,7 @@ geom_segment <- function(mapping = NULL, data = NULL, | |
params = list( | ||
arrow = arrow, | ||
lineend = lineend, | ||
linejoin = linejoin, | ||
na.rm = na.rm, | ||
... | ||
) | ||
|
@@ -84,7 +100,7 @@ GeomSegment <- ggproto("GeomSegment", Geom, | |
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA), | ||
|
||
draw_panel = function(data, panel_params, coord, arrow = NULL, | ||
lineend = "butt", na.rm = FALSE) { | ||
lineend = "butt", linejoin = "round", na.rm = FALSE) { | ||
|
||
data <- remove_missing(data, na.rm = na.rm, | ||
c("x", "y", "xend", "yend", "linetype", "size", "shape"), | ||
|
@@ -100,7 +116,8 @@ GeomSegment <- ggproto("GeomSegment", Geom, | |
fill = alpha(coord$colour, coord$alpha), | ||
lwd = coord$size * .pt, | ||
lty = coord$linetype, | ||
lineend = lineend | ||
lineend = lineend, | ||
linejoin = linejoin | ||
), | ||
arrow = arrow | ||
)) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.