|
|
@ -19,11 +19,17 @@ |
|
|
|
#' often aesthetics, used to set an aesthetic to a fixed value, like |
|
|
|
#' \code{color = "red"} or \code{size = 3}. They may also be parameters |
|
|
|
#' to the paired geom/stat. |
|
|
|
#' @param If \code{horizontal} is \code{FALSE} (the default), the function |
|
|
|
#' will draw the lollipops up from the X axis (i.e. it will set \code{xend} |
|
|
|
#' to \code{x} & \code{yend} to \code{0}). If \code{TRUE}, it wiill set |
|
|
|
#' \code{yend} to \code{y} & \code{xend} to \code{0}). Make sure you map the |
|
|
|
#' \code{x} & \code{y} aesthetics accordingly. |
|
|
|
#' @param point.size the size of the point |
|
|
|
#' @param point.colour the colour of the point |
|
|
|
#' @inheritParams ggplot2::layer |
|
|
|
#' @export |
|
|
|
geom_lollipop <- function(mapping = NULL, data = NULL, ..., |
|
|
|
horizontal = FALSE, |
|
|
|
point.colour = NULL, point.size = NULL, |
|
|
|
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { |
|
|
|
|
|
|
@ -37,6 +43,7 @@ geom_lollipop <- function(mapping = NULL, data = NULL, ..., |
|
|
|
inherit.aes = inherit.aes, |
|
|
|
params = list( |
|
|
|
na.rm = na.rm, |
|
|
|
horizontal = horizontal, |
|
|
|
point.colour = point.colour, |
|
|
|
point.size = point.size, |
|
|
|
... |
|
|
@ -50,18 +57,23 @@ geom_lollipop <- function(mapping = NULL, data = NULL, ..., |
|
|
|
#' @export |
|
|
|
GeomLollipop <- ggproto("GeomLollipop", Geom, |
|
|
|
required_aes = c("x", "y"), |
|
|
|
non_missing_aes = c("size", "shape", "point.colour", "point.size"), |
|
|
|
non_missing_aes = c("size", "shape", "point.colour", "point.size", "horizontal"), |
|
|
|
default_aes = aes( |
|
|
|
shape = 19, colour = "black", size = 0.5, fill = NA, |
|
|
|
alpha = NA, stroke = 0.5 |
|
|
|
), |
|
|
|
|
|
|
|
setup_data = function(data, params) { |
|
|
|
transform(data, xend = x, yend = 0) |
|
|
|
if (params$horizontal) { |
|
|
|
transform(data, yend = y, xend = 0) |
|
|
|
} else { |
|
|
|
transform(data, xend = x, yend = 0) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
draw_group = function(data, panel_scales, coord, |
|
|
|
point.colour = NULL, point.size = NULL) { |
|
|
|
point.colour = NULL, point.size = NULL, |
|
|
|
horizontal = FALSE) { |
|
|
|
|
|
|
|
points <- data |
|
|
|
points$colour <- point.colour %||% data$colour |
|
|
@ -76,3 +88,5 @@ GeomLollipop <- ggproto("GeomLollipop", Geom, |
|
|
|
|
|
|
|
draw_key = draw_key_point |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|