Skip to content

Commit f636f34

Browse files
yutannihilationclauswilke
authored andcommitted
Improve document about handling of NA in geom_path() (#2878)
Closes #2877 * Improve document about handling of NA in geom_path() * Add a section about missing value handling * Add the Oxford comma, and replace the items * Change "in this manner" to "as follows"
1 parent 3f93180 commit f636f34

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

R/geom-path.r

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
#' @seealso
2020
#' [geom_polygon()]: Filled paths (polygons);
2121
#' [geom_segment()]: Line segments
22+
#' @section Missing value handling:
23+
#' `geom_path()`, `geom_line()`, and `geom_step` handle `NA` as follows:
24+
#'
25+
#' * If an `NA` occurs in the middle of a line, it breaks the line. No warning
26+
#' is shown, regardless of whether `na.rm` is `TRUE` or `FALSE`.
27+
#' * If an `NA` occurs at the start or the end of the line and `na.rm` is `FALSE`
28+
#' (default), the `NA` is removed with a warning.
29+
#' * If an `NA` occurs at the start or the end of the line and `na.rm` is `TRUE`,
30+
#' the `NA` is removed silently, without warning.
2231
#' @export
2332
#' @examples
2433
#' # geom_line() is suitable for time series
@@ -57,16 +66,9 @@
5766
#' base + geom_path(size = 10, lineend = "round")
5867
#' base + geom_path(size = 10, linejoin = "mitre", lineend = "butt")
5968
#'
60-
#' # NAs break the line. Use na.rm = T to suppress the warning message
61-
#' df <- data.frame(
62-
#' x = 1:5,
63-
#' y1 = c(1, 2, 3, 4, NA),
64-
#' y2 = c(NA, 2, 3, 4, 5),
65-
#' y3 = c(1, 2, NA, 4, 5)
66-
#' )
67-
#' ggplot(df, aes(x, y1)) + geom_point() + geom_line()
68-
#' ggplot(df, aes(x, y2)) + geom_point() + geom_line()
69-
#' ggplot(df, aes(x, y3)) + geom_point() + geom_line()
69+
#' # You can use NAs to break the line.
70+
#' df <- data.frame(x = 1:5, y = c(1, 2, NA, 4, 5))
71+
#' ggplot(df, aes(x, y)) + geom_point() + geom_line()
7072
#'
7173
#' \donttest{
7274
#' # Setting line type vs colour/size

man/geom_path.Rd

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

0 commit comments

Comments
 (0)