Skip to content

Commit 810c3e5

Browse files
committed
Merge 3362a6b into d9ecaf4
2 parents d9ecaf4 + 3362a6b commit 810c3e5

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

R/trace_generation.R

+7-3
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,15 @@ geom2trace <- list(
574574
# Convert days into milliseconds
575575
x <- as.numeric(x) * 24 * 60 * 60 * 1000
576576
}
577-
L <- list(x=x,
578-
y=data$y,
577+
# if there is more than one y-value for a particular combination of
578+
# x, PANEL, and group; then take the _max_ y.
579+
data$x <- x
580+
dat <- plyr::ddply(data, c("x", "PANEL", if("group"%in%names(data))"group"),
581+
plyr::summarise, count = max(y))
582+
L <- list(x=dat$x,
583+
y=dat$count,
579584
type="bar",
580585
name=params$name,
581-
text=data$text,
582586
marker=list(color=toRGB(params$fill)))
583587
if (!is.null(params$colour)) {
584588
L$marker$line <- list(color=toRGB(params$colour))

tests/testthat/test-ggplot-bar.R

+13
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,16 @@ test_that("geom_bar(position = 'fill') stacks proportions", {
191191
expect_identical(prop, 1)
192192
})
193193

194+
d <- head(diamonds, 50)
195+
gbar <- ggplot(d, aes(cut, price)) + geom_bar(stat = "identity")
196+
197+
test_that("For a given x value, if multiple y exist, sum them. ", {
198+
info <- expect_traces(gbar, 1, "category-names")
199+
expect_identical(info$traces[[1]]$type, "bar")
200+
y <- with(d, tapply(price, cut, sum))
201+
# make sure order of counts match
202+
y <- y[info$traces[[1]]$x]
203+
expect_equal(info$traces[[1]]$y, as.numeric(y))
204+
})
205+
206+

tests/testthat/test-ggplot-categorical.R

-14
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,3 @@ test_that("axis type=category when we plot factors", {
1111

1212
save_outputs(gg, "bar-factor-category")
1313
})
14-
15-
test_that("Bar charts of type=category show category names", {
16-
gbar <- ggplot(d, aes(cut, price)) + geom_bar(stat="identity")
17-
info <- gg2list(gbar)
18-
19-
expect_equal(length(info), 2) # 1 trace + layout
20-
expect_identical(info$kwargs$layout$xaxis$type, "category")
21-
expect_identical(info$kwargs$layout$xaxis$title, "cut")
22-
expect_identical(info$kwargs$layout$yaxis$type, "linear")
23-
expect_true(all(c("Fair", "Good", "Very Good", "Premium", "Ideal") %in%
24-
info[[1]]$x))
25-
26-
save_outputs(gbar, "bar-category-names")
27-
})

0 commit comments

Comments
 (0)