Skip to content

Commit 6094a23

Browse files
authored
Implement geom_linerange(arrow) and geom_pointrange(arrow) (#6482)
* add arrow params * document * accept snapshot * add news bullet
1 parent 8b07991 commit 6094a23

File tree

5 files changed

+47
-25
lines changed

5 files changed

+47
-25
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* The `arrow` and `arrow.fill` arguments are now available in
4+
`geom_linerange()` and `geom_pointrange()` layers (@teunbrand, #6481).
35
* (internal) `zeroGrob()` now returns a `grid::nullGrob()` (#6390).
46
* `stat_ydensity()` now only requires the `x` or `y` aesthetic. The other will
57
be populated with 0, similar to `stat_boxplot()` (@teunbrand, #6600)

R/geom-linerange.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ GeomLinerange <- ggproto(
2727
data
2828
},
2929

30-
draw_panel = function(data, panel_params, coord, lineend = "butt", flipped_aes = FALSE, na.rm = FALSE) {
30+
draw_panel = function(data, panel_params, coord, lineend = "butt",
31+
flipped_aes = FALSE, na.rm = FALSE,
32+
arrow = NULL, arrow.fill = NULL) {
3133
data <- flip_data(data, flipped_aes)
3234
data <- transform(data, xend = x, y = ymin, yend = ymax)
3335
data <- flip_data(data, flipped_aes)
34-
ggname("geom_linerange", GeomSegment$draw_panel(data, panel_params, coord, lineend = lineend, na.rm = na.rm))
36+
grob <- GeomSegment$draw_panel(
37+
data, panel_params, coord,
38+
lineend = lineend, na.rm = na.rm,
39+
arrow = arrow, arrow.fill = arrow.fill
40+
)
41+
ggname("geom_linerange", grob)
3542
},
3643

3744
rename_size = TRUE

R/geom-pointrange.R

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,24 @@ GeomPointrange <- ggproto("GeomPointrange", Geom,
3131
},
3232

3333
draw_panel = function(data, panel_params, coord, lineend = "butt", fatten = 4,
34-
flipped_aes = FALSE, na.rm = FALSE) {
34+
flipped_aes = FALSE, na.rm = FALSE,
35+
arrow = NULL, arrow.fill = NULL) {
3536
line_grob <- GeomLinerange$draw_panel(
3637
data, panel_params, coord, lineend = lineend, flipped_aes = flipped_aes,
37-
na.rm = na.rm
38+
na.rm = na.rm, arrow = arrow, arrow.fill = arrow.fill
3839
)
39-
if (is.null(data[[flipped_names(flipped_aes)$y]]))
40+
41+
skip_point <- is.null(data[[flipped_names(flipped_aes)$y]])
42+
if (skip_point) {
4043
return(line_grob)
44+
}
4145

42-
ggname("geom_pointrange",
43-
gTree(children = gList(
44-
line_grob,
45-
GeomPoint$draw_panel(
46-
transform(data, size = size * fatten),
47-
panel_params, coord, na.rm = na.rm
48-
)
49-
))
46+
point_grob <- GeomPoint$draw_panel(
47+
transform(data, size = size * fatten),
48+
panel_params, coord, na.rm = na.rm
5049
)
50+
grob <- gTree(children = gList(line_grob, point_grob))
51+
ggname("geom_pointrange", grob)
5152
}
5253
)
5354

man/geom_linerange.Rd

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/function-args.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
Code
44
problems
55
Output
6-
[1] "GeomBoxplot : `notch` with `notchwidth`"
7-
[2] "GeomContour : `arrow` with `arrow.fill`"
8-
[3] "GeomCurve : `arrow` with `arrow.fill`"
9-
[4] "GeomDensity2d: `arrow` with `arrow.fill`"
10-
[5] "GeomFunction : `arrow` with `arrow.fill`"
11-
[6] "GeomLine : `arrow` with `arrow.fill`"
12-
[7] "GeomPath : `arrow` with `arrow.fill`"
13-
[8] "GeomQuantile : `arrow` with `arrow.fill`"
14-
[9] "GeomSegment : `arrow` with `arrow.fill`"
15-
[10] "GeomSf : `arrow` with `arrow.fill`"
16-
[11] "GeomSpoke : `arrow` with `arrow.fill`"
17-
[12] "GeomStep : `arrow` with `arrow.fill`"
6+
[1] "GeomBoxplot : `notch` with `notchwidth`"
7+
[2] "GeomContour : `arrow` with `arrow.fill`"
8+
[3] "GeomCurve : `arrow` with `arrow.fill`"
9+
[4] "GeomDensity2d : `arrow` with `arrow.fill`"
10+
[5] "GeomFunction : `arrow` with `arrow.fill`"
11+
[6] "GeomLine : `arrow` with `arrow.fill`"
12+
[7] "GeomLinerange : `arrow` with `arrow.fill`"
13+
[8] "GeomPath : `arrow` with `arrow.fill`"
14+
[9] "GeomPointrange: `arrow` with `arrow.fill`"
15+
[10] "GeomQuantile : `arrow` with `arrow.fill`"
16+
[11] "GeomSegment : `arrow` with `arrow.fill`"
17+
[12] "GeomSf : `arrow` with `arrow.fill`"
18+
[13] "GeomSpoke : `arrow` with `arrow.fill`"
19+
[14] "GeomStep : `arrow` with `arrow.fill`"
1820

1921
# StatXxx$parameters() does not contain partial matches
2022

0 commit comments

Comments
 (0)