diff --git a/NEWS b/NEWS index 09c0f77f6f..b1d24ec8f2 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,10 @@ ggplot2 1.0.1.9000 ---------------------------------------------------------------- +* `geom_crossbar()` sets grouping correctly so you can display multiple + crossbars on one plot. It also makes the default `fatten` argument a little + bigger to make the middle line more obvious (#1125). + * `guide_colorbar()` no longer fails when the legend is empty - previously this often masked misspecifications elsewhere in the plot (#967) diff --git a/R/geom-crossbar.r b/R/geom-crossbar.r index bb6db95fc0..57e332450c 100644 --- a/R/geom-crossbar.r +++ b/R/geom-crossbar.r @@ -12,8 +12,8 @@ #' @export #' @examples #' # See geom_linerange for examples -geom_crossbar <- function (mapping = NULL, data = NULL, stat = "identity", position = "identity", -fatten = 2, ...) { +geom_crossbar <- function(mapping = NULL, data = NULL, stat = "identity", + position = "identity", fatten = 2.5, ...) { GeomCrossbar$new(mapping = mapping, data = data, stat = stat, position = position, fatten = fatten, ...) } @@ -39,7 +39,7 @@ GeomCrossbar <- proto(Geom, { )) } - draw <- function(., data, scales, coordinates, fatten = 2, width = NULL, ...) { + draw <- function(., data, scales, coordinates, fatten = 2.5, width = NULL, ...) { middle <- transform(data, x = xmin, xend = xmax, yend = y, size = size * fatten, alpha = NA) has_notch <- !is.null(data$ynotchlower) && !is.null(data$ynotchupper) && @@ -55,27 +55,39 @@ GeomCrossbar <- proto(Geom, { middle$xend <- middle$xend - notchindent box <- data.frame( - x = c(data$xmin, data$xmin, data$xmin + notchindent, data$xmin, data$xmin, - data$xmax, data$xmax, data$xmax - notchindent, data$xmax, data$xmax, - data$xmin), - y = c(data$ymax, data$ynotchupper, data$y, data$ynotchlower, data$ymin, - data$ymin, data$ynotchlower, data$y, data$ynotchupper, data$ymax, - data$ymax), - alpha = data$alpha, colour = data$colour, size = data$size, - linetype = data$linetype, fill = data$fill, group = data$group, - stringsAsFactors = FALSE) - + x = c( + data$xmin, data$xmin, data$xmin + notchindent, data$xmin, data$xmin, + data$xmax, data$xmax, data$xmax - notchindent, data$xmax, data$xmax, + data$xmin + ), + y = c( + data$ymax, data$ynotchupper, data$y, data$ynotchlower, data$ymin, + data$ymin, data$ynotchlower, data$y, data$ynotchupper, data$ymax, + data$ymax + ), + alpha = data$alpha, + colour = data$colour, + size = data$size, + linetype = data$linetype, fill = data$fill, + group = seq_len(nrow(data)), + stringsAsFactors = FALSE + ) } else { # No notch box <- data.frame( - x = c(data$xmin, data$xmin, data$xmax, data$xmax, data$xmin), - y = c(data$ymax, data$ymin, data$ymin, data$ymax, data$ymax), - alpha = data$alpha, colour = data$colour, size = data$size, - linetype = data$linetype, fill = data$fill, group = data$group, - stringsAsFactors = FALSE) + x = c(data$xmin, data$xmin, data$xmax, data$xmax, data$xmin), + y = c(data$ymax, data$ymin, data$ymin, data$ymax, data$ymax), + alpha = data$alpha, + colour = data$colour, + size = data$size, + linetype = data$linetype, + fill = data$fill, + group = seq_len(nrow(data)), # each bar forms it's own group + stringsAsFactors = FALSE + ) } - ggname(.$my_name(), gTree(children=gList( + ggname(.$my_name(), gTree(children = gList( GeomPolygon$draw(box, scales, coordinates, ...), GeomSegment$draw(middle, scales, coordinates, ...) ))) diff --git a/man/geom_crossbar.Rd b/man/geom_crossbar.Rd index fe8108a78b..e7ab64f461 100644 --- a/man/geom_crossbar.Rd +++ b/man/geom_crossbar.Rd @@ -5,7 +5,7 @@ \title{Hollow bar with middle indicated by horizontal line.} \usage{ geom_crossbar(mapping = NULL, data = NULL, stat = "identity", - position = "identity", fatten = 2, ...) + position = "identity", fatten = 2.5, ...) } \arguments{ \item{mapping}{The aesthetic mapping, usually constructed with