Skip to content

Commit cb3ba4a

Browse files
Add an example for stat_align() (#4940)
1 parent 154fd7f commit cb3ba4a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

R/geom-ribbon.r

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@
4141
#' h +
4242
#' geom_ribbon(aes(ymin = level - 1, ymax = level + 1), fill = "grey70") +
4343
#' geom_line(aes(y = level))
44+
#'
45+
#' # The underlying stat_align() takes care of unaligned data points
46+
#' df <- data.frame(
47+
#' g = c("a", "a", "a", "b", "b", "b"),
48+
#' x = c(1, 3, 5, 2, 4, 6),
49+
#' y = c(2, 5, 1, 3, 6, 7)
50+
#' )
51+
#' a <- ggplot(df, aes(x, y, fill = g)) +
52+
#' geom_area()
53+
#'
54+
#' # Two groups have points on different X values.
55+
#' a + geom_point(size = 8) + facet_grid(g ~ .)
56+
#'
57+
#' # stat_align() interpolates and aligns the value so that the areas can stack
58+
#' # properly.
59+
#' a + geom_point(stat = "align", position = "stack", size = 8)
4460
geom_ribbon <- function(mapping = NULL, data = NULL,
4561
stat = "identity", position = "identity",
4662
...,

man/geom_ribbon.Rd

Lines changed: 16 additions & 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)