forked from tidyverse/ggplot2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeom-vline.r
62 lines (53 loc) · 1.48 KB
/
geom-vline.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#' @include stat-.r
NULL
#' @export
#' @rdname geom_abline
geom_vline <- function(mapping = NULL, data = NULL,
...,
xintercept,
na.rm = FALSE,
show.legend = NA) {
# Act like an annotation
if (!missing(xintercept)) {
# Warn if supplied mapping and/or data is going to be overwritten
if (!is.null(mapping)) {
warn_overwritten_args("geom_vline()", "mapping", "xintercept")
}
if (!is.null(data)) {
warn_overwritten_args("geom_vline()", "data", "xintercept")
}
data <- new_data_frame(list(xintercept = xintercept))
mapping <- aes(xintercept = xintercept)
show.legend <- FALSE
}
layer(
data = data,
mapping = mapping,
stat = StatIdentity,
geom = GeomVline,
position = PositionIdentity,
show.legend = show.legend,
inherit.aes = FALSE,
params = list(
na.rm = na.rm,
...
)
)
}
#' @rdname ggplot2-ggproto
#' @format NULL
#' @usage NULL
#' @export
GeomVline <- ggproto("GeomVline", Geom,
draw_panel = function(data, panel_params, coord) {
ranges <- coord$backtransform_range(panel_params)
data$x <- data$xintercept
data$xend <- data$xintercept
data$y <- ranges$y[1]
data$yend <- ranges$y[2]
GeomSegment$draw_panel(unique(data), panel_params, coord)
},
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA),
required_aes = "xintercept",
draw_key = draw_key_vline
)