Skip to content

Commit 5fbfd8a

Browse files
committed
Allow multiple bars for a given x (this is nice for mapping text, in particular)
1 parent 2e62d57 commit 5fbfd8a

File tree

3 files changed

+2
-34
lines changed

3 files changed

+2
-34
lines changed

R/layers2traces.R

+1-13
Original file line numberDiff line numberDiff line change
@@ -410,19 +410,7 @@ geom2trace.GeomPoint <- function(data, params) {
410410

411411
#' @export
412412
geom2trace.GeomBar <- function(data, params) {
413-
if (!anyDuplicated(data[c("x", "PANEL", "group")])) {
414-
# assuming `layout.barmode='stack'`
415-
data$y <- data$ymax - data$ymin
416-
} else {
417-
# if there is more than one y-value for a particular combination of
418-
# x, PANEL, and group; then take the _max_ y.
419-
data <- plyr::ddply(
420-
data, c("x", "PANEL", "group"),
421-
plyr::summarise,
422-
y = max(y)
423-
)
424-
data <- prefix_class(data, "GeomBar")
425-
}
413+
data$y <- data$ymax - data$ymin
426414
# TODO: use xmin/xmax once plotly.js allows explicit bar widths
427415
# https://github.com/plotly/plotly.js/issues/80
428416
list(

man/group2NA.Rd

-15
This file was deleted.

tests/testthat/test-ggplot-bar.R

+1-6
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,8 @@ test_that("geom_bar(position = 'fill') stacks proportions", {
138138
d <- head(diamonds, 50)
139139
gbar <- ggplot(d, aes(cut, price)) + geom_bar(stat = "identity")
140140

141-
test_that("For a given x value, if multiple y exist, sum them. ", {
141+
test_that("Using identity with multiple y for a given x works ", {
142142
info <- expect_traces(gbar, 1, "category-names")
143-
expect_identical(info$data[[1]]$type, "bar")
144-
y <- with(d, tapply(price, cut, sum))
145-
# make sure order of counts match
146-
y <- y[info$data[[1]]$x]
147-
expect_equal(info$data[[1]]$y, as.numeric(y))
148143
})
149144

150145
p <- ggplot(mtcars, aes(factor(cyl))) + geom_bar() + coord_flip()

0 commit comments

Comments
 (0)