Skip to content

Commit af6f4e8

Browse files
add stat to hline vline and abline (#6633)
1 parent 913e63a commit af6f4e8

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* Fixed regression where `scale_{x,y}_*()` threw an error when an expression
88
object is set to `labels` argument (@yutannihilation, #6617).
99

10+
11+
* Allow `stat` in `geom_hline`, `geom_vline`, and `geom_abline`. (@sierrajohnson, #6559)
12+
1013
# ggplot2 4.0.0
1114

1215
## User facing

R/geom-abline.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ NULL
6969
#' geom_hline(aes(yintercept = wt, colour = wt), mean_wt) +
7070
#' facet_wrap(~ cyl)
7171
geom_abline <- function(mapping = NULL, data = NULL,
72+
stat = "identity",
7273
...,
7374
slope,
7475
intercept,
7576
na.rm = FALSE,
76-
show.legend = NA) {
77+
show.legend = NA,
78+
inherit.aes = FALSE) {
7779

7880
# If nothing set, default to y = x
7981
if (is.null(mapping) && missing(slope) && missing(intercept)) {
@@ -108,11 +110,11 @@ geom_abline <- function(mapping = NULL, data = NULL,
108110
layer(
109111
data = data,
110112
mapping = mapping,
111-
stat = StatIdentity,
113+
stat = stat,
112114
geom = GeomAbline,
113115
position = PositionIdentity,
114116
show.legend = show.legend,
115-
inherit.aes = FALSE,
117+
inherit.aes = inherit.aes,
116118
params = list2(
117119
na.rm = na.rm,
118120
...

R/geom-hline.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ NULL
44
#' @export
55
#' @rdname geom_abline
66
geom_hline <- function(mapping = NULL, data = NULL,
7-
position = "identity",
7+
stat = "identity", position = "identity",
88
...,
99
yintercept,
1010
na.rm = FALSE,
11-
show.legend = NA) {
11+
show.legend = NA,
12+
inherit.aes = FALSE) {
1213

1314
# Act like an annotation
1415
if (!missing(yintercept)) {
@@ -28,11 +29,11 @@ geom_hline <- function(mapping = NULL, data = NULL,
2829
layer(
2930
data = data,
3031
mapping = mapping,
31-
stat = StatIdentity,
32+
stat = stat,
3233
geom = GeomHline,
3334
position = position,
3435
show.legend = show.legend,
35-
inherit.aes = FALSE,
36+
inherit.aes = inherit.aes,
3637
params = list2(
3738
na.rm = na.rm,
3839
...

R/geom-vline.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ NULL
44
#' @export
55
#' @rdname geom_abline
66
geom_vline <- function(mapping = NULL, data = NULL,
7-
position = "identity",
7+
stat = "identity", position = "identity",
88
...,
99
xintercept,
1010
na.rm = FALSE,
11-
show.legend = NA) {
11+
show.legend = NA,
12+
inherit.aes = FALSE) {
1213

1314
# Act like an annotation
1415
if (!missing(xintercept)) {
@@ -28,11 +29,11 @@ geom_vline <- function(mapping = NULL, data = NULL,
2829
layer(
2930
data = data,
3031
mapping = mapping,
31-
stat = StatIdentity,
32+
stat = stat,
3233
geom = GeomVline,
3334
position = position,
3435
show.legend = show.legend,
35-
inherit.aes = FALSE,
36+
inherit.aes = inherit.aes,
3637
params = list2(
3738
na.rm = na.rm,
3839
...

man/geom_abline.Rd

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

0 commit comments

Comments
 (0)