From 0750e55113794633579429d2fc0790febdd5631f Mon Sep 17 00:00:00 2001 From: Thomas Knecht Date: Mon, 16 Sep 2019 13:47:58 +0200 Subject: [PATCH] Add time series example --- R/position-nudgestack.R | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/R/position-nudgestack.R b/R/position-nudgestack.R index 60e67169dd..a2837ba90e 100644 --- a/R/position-nudgestack.R +++ b/R/position-nudgestack.R @@ -13,13 +13,23 @@ #' This is useful if you're rotating both the plot and legend. #' @export #' @examples -#' data <- mtcars -#' ggplot() + -#' geom_col( -#' data, -#' aes(x = cyl, y = gear, fill = gear), -#' position = position_nudgestack(x = 1) +#' library(dplyr) +#' library(ggplot2) +#' ESM <- data.frame( +#' as.matrix(EuStockMarkets), +#' date = as.Date(paste(1, zoo::as.yearmon(time(EuStockMarkets))), +#' format = "%d %b %Y" #' ) +#' ) +#' +#' ESM_prep <- ESM %>% +#' tidyr::gather(key = key, value = value, -date) %>% +#' group_by(date, key) %>% +#' summarize(value = mean(value)) %>% +#' filter(date >= "1995-01-01" & date <= "1997-12-01") +#' +#' ggplot(data = ESM_prep, mapping = aes(x = date, y = value, fill = key)) + +#' geom_col(position = position_nudgestack(x = 15)) position_nudgestack <- function(x = 0, y = 0, vjust = 1, reverse = FALSE) { ggproto(NULL, PositionNudgeStack, x = x, @@ -36,7 +46,6 @@ position_nudgestack <- function(x = 0, y = 0, vjust = 1, reverse = FALSE) { PositionNudgeStack <- ggproto("PositionNudgeStack", Position, x = 0, y = 0, - type = NULL, vjust = 1, fill = FALSE, reverse = FALSE,