Skip to content

added fill to gpar in geom_curve() #2375

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 5 commits into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
of padding between elements (@karawoo, #2143). A `reverse` parameter allows
you to reverse the placement order of bars and boxes (@karawoo, #2171).

* The `geom_segment()` and `geom_curve()` geoms both have a new
`arrow.fill` parameter which enables specifying a separate fill colour for
closed arrowheads. (@hrbrmstr and @clauswilke, #2375).

* The `expand` argument for `scale_*_continuous()` and `scale_*_discrete()`
now accepts separate expansion values for the lower and upper range
limits. The expansion limits can be specified using the convenience
Expand Down
10 changes: 9 additions & 1 deletion R/geom-curve.r
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ geom_curve <- function(mapping = NULL, data = NULL,
angle = 90,
ncp = 5,
arrow = NULL,
arrow.fill = NULL,
lineend = "butt",
na.rm = FALSE,
show.legend = NA,
Expand All @@ -22,6 +23,7 @@ geom_curve <- function(mapping = NULL, data = NULL,
inherit.aes = inherit.aes,
params = list(
arrow = arrow,
arrow.fill = arrow.fill,
curvature = curvature,
angle = angle,
ncp = ncp,
Expand All @@ -38,21 +40,27 @@ geom_curve <- function(mapping = NULL, data = NULL,
#' @usage NULL
#' @export
GeomCurve <- ggproto("GeomCurve", GeomSegment,
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA),
draw_panel = function(data, panel_params, coord, curvature = 0.5, angle = 90,
ncp = 5, arrow = NULL, lineend = "butt", na.rm = FALSE) {
ncp = 5, arrow = NULL, arrow.fill, lineend = "butt", na.rm = FALSE) {

if (!coord$is_linear()) {
warning("geom_curve is not implemented for non-linear coordinates",
call. = FALSE)
}

trans <- coord$transform(data, panel_params)

arrow.fill <- arrow.fill %||% trans$colour

curveGrob(
trans$x, trans$y, trans$xend, trans$yend,
default.units = "native",
curvature = curvature, angle = angle, ncp = ncp,
square = FALSE, squareShape = 1, inflect = FALSE, open = TRUE,
gp = gpar(
col = alpha(trans$colour, trans$alpha),
fill = alpha(arrow.fill, trans$alpha),
lwd = trans$size * .pt,
lty = trans$linetype,
lineend = lineend),
Expand Down
9 changes: 7 additions & 2 deletions R/geom-segment.r
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#' @inheritParams layer
#' @inheritParams geom_point
#' @param arrow specification for arrow heads, as created by arrow().
#' @param arrow.fill fill color to use for the arrow head (if closed). `NULL`
#' means use `colour` aesthetic.
#' @param lineend Line end style (round, butt, square).
#' @param linejoin Line join style (round, mitre, bevel).
#' @seealso [geom_path()] and [geom_line()] for multi-
Expand Down Expand Up @@ -67,6 +69,7 @@ geom_segment <- function(mapping = NULL, data = NULL,
stat = "identity", position = "identity",
...,
arrow = NULL,
arrow.fill = NULL,
lineend = "butt",
linejoin = "round",
na.rm = FALSE,
Expand All @@ -82,6 +85,7 @@ geom_segment <- function(mapping = NULL, data = NULL,
inherit.aes = inherit.aes,
params = list(
arrow = arrow,
arrow.fill = arrow.fill,
lineend = lineend,
linejoin = linejoin,
na.rm = na.rm,
Expand All @@ -99,7 +103,7 @@ GeomSegment <- ggproto("GeomSegment", Geom,
non_missing_aes = c("linetype", "size", "shape"),
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA),

draw_panel = function(data, panel_params, coord, arrow = NULL,
draw_panel = function(data, panel_params, coord, arrow = NULL, arrow.fill = NULL,
lineend = "butt", linejoin = "round", na.rm = FALSE) {

data <- remove_missing(data, na.rm = na.rm,
Expand All @@ -109,11 +113,12 @@ GeomSegment <- ggproto("GeomSegment", Geom,

if (coord$is_linear()) {
coord <- coord$transform(data, panel_params)
arrow.fill <- arrow.fill %||% coord$colour
return(segmentsGrob(coord$x, coord$y, coord$xend, coord$yend,
default.units = "native",
gp = gpar(
col = alpha(coord$colour, coord$alpha),
fill = alpha(coord$colour, coord$alpha),
fill = alpha(arrow.fill, coord$alpha),
lwd = coord$size * .pt,
lty = coord$linetype,
lineend = lineend,
Expand Down
11 changes: 7 additions & 4 deletions man/geom_segment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gg-add.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.