Skip to content

Commit bcc75a3

Browse files
Thomas KnechtThomas Knecht
Thomas Knecht
authored and
Thomas Knecht
committed
Add time series example
1 parent 01d7db0 commit bcc75a3

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

R/position-nudgestack.R

+16-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,23 @@
1313
#' This is useful if you're rotating both the plot and legend.
1414
#' @export
1515
#' @examples
16-
#' data <- mtcars
17-
#' ggplot() +
18-
#' geom_col(
19-
#' data,
20-
#' aes(x = cyl, y = gear, fill = gear),
21-
#' position = position_nudgestack(x = 1)
16+
#' library(dplyr)
17+
#' library(ggplot2)
18+
#' ESM <- data.frame(
19+
#' as.matrix(EuStockMarkets),
20+
#' date = as.Date(paste(1, zoo::as.yearmon(time(EuStockMarkets))),
21+
#' format = "%d %b %Y"
2222
#' )
23+
#' )
24+
#'
25+
#' ESM_prep <- ESM %>%
26+
#' tidyr::gather(key = key, value = value, -date) %>%
27+
#' group_by(date, key) %>%
28+
#' summarize(value = mean(value)) %>%
29+
#' filter(date >= "1995-01-01" & date <= "1997-12-01")
30+
#'
31+
#' ggplot(data = ESM_prep, mapping = aes(x = date, y = value, fill = key)) +
32+
#' geom_col(position = position_nudgestack(x = 15))
2333
position_nudgestack <- function(x = 0, y = 0, vjust = 1, reverse = FALSE) {
2434
ggproto(NULL, PositionNudgeStack,
2535
x = x,
@@ -36,7 +46,6 @@ position_nudgestack <- function(x = 0, y = 0, vjust = 1, reverse = FALSE) {
3646
PositionNudgeStack <- ggproto("PositionNudgeStack", Position,
3747
x = 0,
3848
y = 0,
39-
type = NULL,
4049
vjust = 1,
4150
fill = FALSE,
4251
reverse = FALSE,

0 commit comments

Comments
 (0)