Skip to content

Commit 75b4ca8

Browse files
committed
position identity means barmode stack; fix date conversion
1 parent b938fda commit 75b4ca8

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

R/trace_generation.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,8 @@ layer2traces <- function(l, d, misc) {
250250
if (g$geom == "bar") {
251251
tr$bargap <- if (exists("bargap")) bargap else "default"
252252
pos <- l$position$.super$objname
253-
tr$barmode <- if (pos == "identity") {
254-
"overlay"
255-
} else if (pos %in% c("stack", "fill")) {
253+
#browser()
254+
tr$barmode <- if (pos %in% c("identity", "stack", "fill")) {
256255
"stack"
257256
} else "group"
258257
}
@@ -577,6 +576,13 @@ geom2trace <- list(
577576
},
578577
bar=function(data, params) {
579578
x <- if ("x.name" %in% names(data)) data$x.name else data$x
579+
if (inherits(x, "POSIXt")) {
580+
# Convert seconds into milliseconds
581+
x <- as.numeric(x) * 1000
582+
} else if (inherits(x, "Date")) {
583+
# Convert days into milliseconds
584+
x <- as.numeric(x) * 24 * 60 * 60 * 1000
585+
}
580586
L <- list(x=x,
581587
y=data$y,
582588
type="bar",

tests/testthat/test-ggplot-bar.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ test_that("position_stack is translated to barmode=stack", {
4444
expect_identical(info$kwargs$layout$barmode, "stack")
4545
})
4646

47-
test_that("position_identity is translated to barmode=overlay", {
47+
test_that("position_identity is translated to barmode=stack", {
4848
gg.identity <- gg + geom_bar(stat="identity", position="identity")
4949
info <- expect_traces(gg.identity, 2, "identity")
5050
trs <- info$traces
5151
trace.names <- sapply(trs[1:2], "[[", "name")
5252
expect_true(all(c("Math", "Bio") %in% trace.names))
53-
expect_identical(info$kwargs$layout$barmode, "overlay")
53+
expect_identical(info$kwargs$layout$barmode, "stack")
5454
})
5555

5656
test_that("dates work well with bar charts", {

0 commit comments

Comments
 (0)