Skip to content

Commit

Permalink
Add time series example
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Knecht authored and ThomasKnecht committed Oct 7, 2019
1 parent ce942ac commit 0750e55
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions R/position-nudgestack.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 0750e55

Please sign in to comment.