Skip to content

Commit e1ee2ca

Browse files
committed
document
1 parent 5ecc4a2 commit e1ee2ca

11 files changed

+141
-25
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Collate:
207207
'plot.R'
208208
'position-.R'
209209
'position-collide.R'
210+
'position-connection.R'
210211
'position-dodge.R'
211212
'position-dodge2.R'
212213
'position-identity.R'

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ export(GuideNone)
229229
export(GuideOld)
230230
export(Layout)
231231
export(Position)
232+
export(PositionConnect)
232233
export(PositionDodge)
233234
export(PositionDodge2)
234235
export(PositionFill)
@@ -511,6 +512,7 @@ export(old_guide)
511512
export(panel_cols)
512513
export(panel_rows)
513514
export(pattern_alpha)
515+
export(position_connect)
514516
export(position_dodge)
515517
export(position_dodge2)
516518
export(position_fill)

R/position-connection.R

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,56 @@
1-
2-
1+
#' Connect observations
2+
#'
3+
#' A line connecting two points is usually drawn as a straight segment. This
4+
#' position adjustment gives additional options for how two points are connected.
5+
#'
6+
#' @param connection
7+
#' A specification of how to points are connected. Can be one of the following:
8+
#' * A string giving a named connection. These options are:
9+
#' * `"hv"` to first jump horizontally, then vertically.
10+
#' * `"vh"` to first jump vertically, then horizontally.
11+
#' * `"mid"` to step half-way between adjacent x-values.
12+
#' * `"linear"` to use a straight segment.
13+
#' * A numeric matrix with two columns giving x and y coordinates respectively.
14+
#' The coordinates should describe points on a path that connect point A at
15+
#' location (0, 0) to point B at location (1, 1). At least one of these two
16+
#' points is expected to be included in the coordinates.
17+
#'
18+
#' @family position adjustments
19+
#' @export
20+
#'
21+
#' @examples
22+
#' # Mirroring `geom_step()`
23+
#' ggplot(head(economics, 20), aes(date, unemploy)) +
24+
#' geom_line(position = "connect")
25+
#'
26+
#' # Making a histogram without bars
27+
#' ggplot(faithful, aes(waiting)) +
28+
#' geom_area(
29+
#' stat = "bin", bins = 20, pad = TRUE,
30+
#' position = position_connect("mid")
31+
#' )
32+
#'
33+
#' # Using custom connections with a matrix.
34+
#' # Note that point A at (0, 0) is not included, but point B at (1, 1) is.
35+
#' zigzag <- cbind(c(0.4, 0.6, 1), c(0.75, 0.25, 1))
36+
#' x <- seq(0, 1, length.out = 20)[-1]
37+
#' smooth <- cbind(x, scales::rescale(1 / (1 + exp(-(x * 10 - 5)))))
38+
#'
39+
#' ggplot(head(huron, 10), aes(year, level)) +
40+
#' geom_line(position = position_connect(zigzag), aes(colour = "zigzag")) +
41+
#' geom_line(position = position_connect(smooth), aes(colour = "smooth")) +
42+
#' geom_point()
343
position_connect <- function(connection = "hv") {
444
ggproto(
545
NULL, PositionConnect,
646
connection = connection
747
)
848
}
949

50+
#' @rdname ggplot2-ggproto
51+
#' @format NULL
52+
#' @usage NULL
53+
#' @export
1054
PositionConnect <- ggproto(
1155
"PositionConnect", Position,
1256
connection = "hv",
@@ -69,6 +113,7 @@ validate_connection <- function(connection, call = caller_env()) {
69113
connection
70114
}
71115

116+
# Interpolates between every point and the next
72117
build_connection <- function(data, connection) {
73118

74119
n <- nrow(data)

man/ggplot2-ggproto.Rd

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

man/position_connect.Rd

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

man/position_dodge.Rd

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

man/position_identity.Rd

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

man/position_jitter.Rd

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

man/position_jitterdodge.Rd

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

man/position_nudge.Rd

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

0 commit comments

Comments
 (0)