Browse Source

horizontal param for lollipops

pull/15/head
Bob Rudis 8 years ago
parent
commit
144ad18781
  1. 20
      R/geom_lollipop.r
  2. 12
      man/geom_lollipop.Rd

20
R/geom_lollipop.r

@ -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
)

12
man/geom_lollipop.Rd

@ -4,9 +4,9 @@
\alias{geom_lollipop}
\title{Lollipop charts}
\usage{
geom_lollipop(mapping = NULL, data = NULL, ..., point.colour = NULL,
point.size = NULL, na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE)
geom_lollipop(mapping = NULL, data = NULL, ..., horizontal = FALSE,
point.colour = NULL, point.size = NULL, na.rm = FALSE,
show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
@ -48,6 +48,12 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
\item{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.}
}
\description{
The lollipop geom is used to create lollipop charts.

Loading…
Cancel
Save