Skip to content

Commit 3aef2d4

Browse files
committed
Set proper bar orientation when we detect geom_bar() + coord_flip(). Fixes #390
1 parent 1b6308a commit 3aef2d4

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: R/ggplotly.R

+1
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ gg2list <- function(p) {
940940
y <- tr[["y"]]
941941
tr[["y"]] <- x
942942
tr[["x"]] <- y
943+
if (isTRUE(tr[["type"]] == "bar")) tr$orientation <- "h"
943944
flipped.traces[[trace.i]] <- tr
944945
}
945946
x <- layout[["xaxis"]]

Diff for: tests/testthat/test-ggplot-bar.R

+8
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,11 @@ test_that("For a given x value, if multiple y exist, sum them. ", {
184184
y <- y[info$data[[1]]$x]
185185
expect_equal(info$data[[1]]$y, as.numeric(y))
186186
})
187+
188+
p <- ggplot(mtcars, aes(factor(cyl))) + geom_bar() + coord_flip()
189+
190+
test_that("geom_bar() + coord_flip() works", {
191+
info <- expect_traces(g, 1, "coord-flip")
192+
expect_identical(info$data[[1]]$orientation, "h")
193+
})
194+

0 commit comments

Comments
 (0)