Skip to content

Commit 069abcb

Browse files
committed
Fix grouping error in geom_crossbar
Also bump up fatten to make middles more obvious. Fixes #1125
1 parent a6e045e commit 069abcb

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
ggplot2 1.0.1.9000
22
----------------------------------------------------------------
33

4+
* `geom_crossbar()` sets grouping correctly so you can display multiple
5+
crossbars on one plot. It also makes the default `fatten` argument a little
6+
bigger to make the middle line more obvious (#1125).
7+
48
* `guide_colorbar()` no longer fails when the legend is empty - previously
59
this often masked misspecifications elsewhere in the plot (#967)
610

R/geom-crossbar.r

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#' @export
1313
#' @examples
1414
#' # See geom_linerange for examples
15-
geom_crossbar <- function (mapping = NULL, data = NULL, stat = "identity", position = "identity",
16-
fatten = 2, ...) {
15+
geom_crossbar <- function(mapping = NULL, data = NULL, stat = "identity",
16+
position = "identity", fatten = 2.5, ...) {
1717
GeomCrossbar$new(mapping = mapping, data = data, stat = stat,
1818
position = position, fatten = fatten, ...)
1919
}
@@ -39,7 +39,7 @@ GeomCrossbar <- proto(Geom, {
3939
))
4040
}
4141

42-
draw <- function(., data, scales, coordinates, fatten = 2, width = NULL, ...) {
42+
draw <- function(., data, scales, coordinates, fatten = 2.5, width = NULL, ...) {
4343
middle <- transform(data, x = xmin, xend = xmax, yend = y, size = size * fatten, alpha = NA)
4444

4545
has_notch <- !is.null(data$ynotchlower) && !is.null(data$ynotchupper) &&
@@ -55,27 +55,39 @@ GeomCrossbar <- proto(Geom, {
5555
middle$xend <- middle$xend - notchindent
5656

5757
box <- data.frame(
58-
x = c(data$xmin, data$xmin, data$xmin + notchindent, data$xmin, data$xmin,
59-
data$xmax, data$xmax, data$xmax - notchindent, data$xmax, data$xmax,
60-
data$xmin),
61-
y = c(data$ymax, data$ynotchupper, data$y, data$ynotchlower, data$ymin,
62-
data$ymin, data$ynotchlower, data$y, data$ynotchupper, data$ymax,
63-
data$ymax),
64-
alpha = data$alpha, colour = data$colour, size = data$size,
65-
linetype = data$linetype, fill = data$fill, group = data$group,
66-
stringsAsFactors = FALSE)
67-
58+
x = c(
59+
data$xmin, data$xmin, data$xmin + notchindent, data$xmin, data$xmin,
60+
data$xmax, data$xmax, data$xmax - notchindent, data$xmax, data$xmax,
61+
data$xmin
62+
),
63+
y = c(
64+
data$ymax, data$ynotchupper, data$y, data$ynotchlower, data$ymin,
65+
data$ymin, data$ynotchlower, data$y, data$ynotchupper, data$ymax,
66+
data$ymax
67+
),
68+
alpha = data$alpha,
69+
colour = data$colour,
70+
size = data$size,
71+
linetype = data$linetype, fill = data$fill,
72+
group = seq_len(nrow(data)),
73+
stringsAsFactors = FALSE
74+
)
6875
} else {
6976
# No notch
7077
box <- data.frame(
71-
x = c(data$xmin, data$xmin, data$xmax, data$xmax, data$xmin),
72-
y = c(data$ymax, data$ymin, data$ymin, data$ymax, data$ymax),
73-
alpha = data$alpha, colour = data$colour, size = data$size,
74-
linetype = data$linetype, fill = data$fill, group = data$group,
75-
stringsAsFactors = FALSE)
78+
x = c(data$xmin, data$xmin, data$xmax, data$xmax, data$xmin),
79+
y = c(data$ymax, data$ymin, data$ymin, data$ymax, data$ymax),
80+
alpha = data$alpha,
81+
colour = data$colour,
82+
size = data$size,
83+
linetype = data$linetype,
84+
fill = data$fill,
85+
group = seq_len(nrow(data)), # each bar forms it's own group
86+
stringsAsFactors = FALSE
87+
)
7688
}
7789

78-
ggname(.$my_name(), gTree(children=gList(
90+
ggname(.$my_name(), gTree(children = gList(
7991
GeomPolygon$draw(box, scales, coordinates, ...),
8092
GeomSegment$draw(middle, scales, coordinates, ...)
8193
)))

man/geom_crossbar.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
\title{Hollow bar with middle indicated by horizontal line.}
66
\usage{
77
geom_crossbar(mapping = NULL, data = NULL, stat = "identity",
8-
position = "identity", fatten = 2, ...)
8+
position = "identity", fatten = 2.5, ...)
99
}
1010
\arguments{
1111
\item{mapping}{The aesthetic mapping, usually constructed with

0 commit comments

Comments
 (0)