diff --git a/NAMESPACE b/NAMESPACE index 6ad256f..f8c0a1c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(add_lines) export(calculate_timing) export(check_quality) export(convplot) +export(coord_stack) export(geom_token) export(geom_turn) export(GeomToken) @@ -17,3 +18,5 @@ export(theme_turnPlot) export(tokenize) import(ggplot2) import(viridis) +importFrom(ggplot2,Geom) +importFrom(ggplot2,ggproto) diff --git a/R/coord-stack.R b/R/coord-stack.R new file mode 100644 index 0000000..cbde62d --- /dev/null +++ b/R/coord-stack.R @@ -0,0 +1,26 @@ +#' Coordinate system that stacks a wide plot to multiple layers +#' +#' @param width Width of the stacked layers in seconds +#' @export +#' @inheritParams ggplot2::coord_trans +coord_stack <- function(width, ...) { + width <- width * 1000 # convert to ms + ggplot2::coord_trans(x = stacking_x_axis(width), ...) +} + + +stacking_x_axis <- function(width){ + force(width) + trans <- function(x) { + x <- x %% width + x + } + + scales::trans_new( + name = "stackx", + transform = trans, + inverse = function(x){ + x/width + } + ) +} diff --git a/R/geom_token.R b/R/geom_token.R index d4acc22..f61cef8 100644 --- a/R/geom_token.R +++ b/R/geom_token.R @@ -26,9 +26,8 @@ geom_token <- function(data, mapping = NULL, #' GeomToken #' -#' @rdname ggplot2-ggproto -#' @format NULL -#' @usage NULL +#' @rdname ggproto +#' @importFrom ggplot2 ggproto Geom #' @export GeomToken <- ggproto( "GeomToken", Geom, diff --git a/R/geom_turn.R b/R/geom_turn.R index 7436792..6a7039c 100644 --- a/R/geom_turn.R +++ b/R/geom_turn.R @@ -26,9 +26,8 @@ geom_turn <- function(mapping = NULL, data = NULL, #' GeomTurn #' -#' @rdname ggplot2-ggproto -#' @format NULL -#' @usage NULL +#' @rdname ggproto +#' @importFrom ggplot2 ggproto Geom #' @export GeomTurn <- ggproto( "GeomTurn", Geom, diff --git a/man/coord_stack.Rd b/man/coord_stack.Rd new file mode 100644 index 0000000..d91c729 --- /dev/null +++ b/man/coord_stack.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/coord-stack.R +\name{coord_stack} +\alias{coord_stack} +\title{Coordinate system that stacks a wide plot to multiple layers} +\usage{ +coord_stack(width, ...) +} +\arguments{ +\item{width}{Width of the stacked layers in seconds} +} +\description{ +Coordinate system that stacks a wide plot to multiple layers +} diff --git a/man/ggplot2-ggproto.Rd b/man/ggplot2-ggproto.Rd deleted file mode 100644 index fb323f3..0000000 --- a/man/ggplot2-ggproto.Rd +++ /dev/null @@ -1,13 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/geom_token.R, R/geom_turn.R -\docType{data} -\name{GeomToken} -\alias{GeomToken} -\alias{GeomTurn} -\title{GeomToken} -\description{ -GeomToken - -GeomTurn -} -\keyword{datasets} diff --git a/man/ggproto.Rd b/man/ggproto.Rd new file mode 100644 index 0000000..3489355 --- /dev/null +++ b/man/ggproto.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/geom_token.R, R/geom_turn.R +\docType{data} +\name{GeomToken} +\alias{GeomToken} +\alias{GeomTurn} +\title{GeomToken} +\format{ +An object of class \code{GeomToken} (inherits from \code{Geom}, \code{ggproto}, \code{gg}) of length 4. + +An object of class \code{GeomTurn} (inherits from \code{Geom}, \code{ggproto}, \code{gg}) of length 6. +} +\usage{ +GeomToken + +GeomTurn +} +\description{ +GeomToken + +GeomTurn +} +\keyword{datasets}