|
3 | 3 | #' @section Aesthetics:
|
4 | 4 | #' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "curve")}
|
5 | 5 | #'
|
6 |
| -#' @inheritParams geom_point |
7 |
| -#' @param curvature see curveGrob |
8 |
| -#' @param angle see curveGrob |
9 |
| -#' @param ncp see curveGrob |
| 6 | +#' @inheritParams grid::curveGrob |
| 7 | +#' @param curvature A numeric value giving the amount of curvature. Negative values produce left-hand curves, positive values produce right-hand curves, and zero produces a straight line. (see curveGrob) |
| 8 | +#' @param angle A numeric value between 0 and 180, giving an amount to skew the control points of the curve. Values less than 90 skew the curve towards the start point and values greater than 90 skew the curve towards the end point. (see curveGrob) |
| 9 | +#' @param ncp The number of control points used to draw the curve. More control points creates a smoother curve. (see curveGrob) |
10 | 10 | #' @param arrow specification for arrow heads, as created by arrow()
|
11 | 11 | #' @param lineend Line end style (round, butt, square)
|
12 | 12 | #' @seealso \code{\link{geom_segment}}, \code{\link{geom_path}} and \code{\link{geom_line}} for multi-
|
|
16 | 16 | #' # Adding curve segments
|
17 | 17 | #' library(grid) # needed for arrow function
|
18 | 18 | #' b <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
|
19 |
| -#' b + geom_curve(aes(x = 2, y = 15, xend = 2, yend = 25, curvature = 0.2)) |
20 |
| -#' b + geom_curve(aes(x = 2, y = 15, xend = 3, yend = 15, ncp = 2)) |
| 19 | +#' b + geom_curve(aes(x = 2, y = 15, xend = 2, yend = 25), curvature = 0.2) |
| 20 | +#' b + geom_curve(aes(x = 2, y = 15, xend = 3, yend = 15), ncp = 2) |
21 | 21 | #' b + geom_curve(aes(x = 5, y = 30, xend = 3.5, yend = 25), arrow = arrow(length = unit(0.5, "cm")))
|
22 | 22 |
|
23 | 23 |
|
24 |
| -geom_curve <- function (mapping = NULL, data = NULL, stat = "identity", |
25 |
| - position = "identity", arrow = NULL, lineend = "butt", na.rm = FALSE, ...) { |
| 24 | +geom_curve <- function (mapping = NULL, data = NULL, stat = "identity", position = "identity", |
| 25 | + curvature = 1, angle = 90, ncp = 1, arrow = NULL, lineend = "butt", |
| 26 | + na.rm = FALSE, ...) { |
26 | 27 |
|
27 | 28 | GeomCurve$new(mapping = mapping, data = data, stat = stat,
|
28 |
| - position = position, arrow = arrow, lineend = lineend, na.rm = na.rm, ...) |
| 29 | + position = position, arrow = arrow, curvature = curvature, angle = angle, |
| 30 | + ncp = ncp, lineend = lineend, na.rm = na.rm, ...) |
29 | 31 | }
|
30 | 32 |
|
31 | 33 | GeomCurve <- proto(Geom, {
|
32 | 34 | objname <- "curve"
|
33 | 35 |
|
34 |
| - draw <- function(., data, scales, coordinates, arrow = NULL, |
35 |
| - lineend = "butt", na.rm = FALSE, ...) { |
| 36 | + draw <- function(., data, scales, coordinates, curvature, angle, ncp, |
| 37 | + arrow, lineend, na.rm, ...) { |
36 | 38 |
|
37 | 39 | data <- remove_missing(data, na.rm = na.rm,
|
38 |
| - c("x", "y", "xend", "yend", "linetype", "size", "shape", "curvature", "angle", "ncp"), |
| 40 | + c("x", "y", "xend", "yend", "linetype", "size", "shape"), |
39 | 41 | name = "geom_curve")
|
40 | 42 |
|
41 | 43 | if (empty(data)) return(zeroGrob())
|
42 | 44 |
|
43 | 45 | if (is.linear(coordinates)) {
|
44 | 46 | return(with(coord_transform(coordinates, data, scales),
|
45 | 47 | curveGrob(x, y, xend, yend, default.units="native",
|
46 |
| - curvature=curvature[1], angle=angle[1], ncp=ncp[1], |
| 48 | + curvature=curvature, angle=angle, ncp=ncp, |
47 | 49 | square = FALSE, squareShape = 1,
|
48 | 50 | inflect = FALSE, open = TRUE,
|
49 | 51 | gp = gpar(col=alpha(colour, alpha), fill = alpha(colour, alpha),
|
50 | 52 | lwd=size * .pt, lty=linetype, lineend = lineend),
|
51 | 53 | arrow = arrow)
|
52 | 54 | ))
|
53 | 55 | }
|
54 |
| - print("geom_curve is not implemented for non-linear coordinates") |
| 56 | + warning("geom_curve is not implemented for non-linear coordinates") |
55 | 57 | return(zeroGrob())
|
56 | 58 | }
|
57 | 59 |
|
58 | 60 |
|
59 | 61 | default_stat <- function(.) StatIdentity
|
60 | 62 | required_aes <- c("x", "y", "xend", "yend")
|
61 |
| - default_aes <- function(.) aes(colour="black", size=0.5, linetype=1, alpha = NA, curvature = 1, angle = 90, ncp = 1) |
| 63 | + default_aes <- function(.) aes(colour="black", size=0.5, linetype=1, alpha = NA) |
62 | 64 | guide_geom <- function(.) "path"
|
63 | 65 |
|
64 | 66 | })
|
0 commit comments