R/geomtimeline.R

# geom_timeline()
library(ggplot2)
library(grid)
GeomTimeline <- ggproto("GeomTimeline", Geom,
                        required_aes = c("x"),
                        default_aes = aes(y = 0,
                                          shape = 21,
                                          color = "black",
                                          size = 1.5,
                                          fill = "black",
                                          alpha = NA,
                                          stroke = 0.5),
                        draw_key = draw_key_point,
                        draw_panel = function(data, panel_scales, coord){
                          coords <- coord$transform(data, panel_scales)
                          grid::pointsGrob(x = coords$x,
                                           y = coords$y,
                                           pch = coords$shape,
                                           gp = gpar(col = alpha(coords$colour,
                                                                 coords$alpha),
                                                     fill = alpha(coords$fill,
                                                                  coords$alpha),
                                                     fontsize = coords$size * .pt + coords$stroke * .stroke/2,
                                                     lwd = coords$stroke * .stroke/2))
                        })

geom_timeline <- function (mapping = NULL, data = NULL, stat = "identity",
                           position = "identity", ..., na.rm = FALSE,
                           show.legend = NA, inherit.aes = TRUE){
  ggplot2::layer(data = data,
                 mapping = mapping,
                 stat = stat,
                 geom = GeomTimeline,
                 position = position,
                 show.legend = show.legend,
                 inherit.aes = inherit.aes,
                 params = list(na.rm = na.rm, ...))
}
burch-cm/noaaview documentation built on May 6, 2019, 6:03 p.m.