Skip to content

Commit

Permalink
fix bad equality statement in CoordFlip logic, fixes #1074
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Mar 28, 2018
1 parent 380d5f4 commit 6e93169
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,8 @@ gg2list <- function(p, width = NULL, height = NULL,
for (i in seq_along(traces)) {
tr <- traces[[i]]
# flipping logic for bar positioning is in geom2trace.GeomBar
if (tr$type != "bar") traces[[i]][c("x", "y")] <- tr[c("y", "x")]
if (tr$type %in% "box") {
if (!identical(tr$type, "bar")) traces[[i]][c("x", "y")] <- tr[c("y", "x")]
if (identical(tr$type, "box")) {
traces[[i]]$orientation <- "h"
traces[[i]]$hoverinfo <- "x"
}
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-ggplot-point.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ test_that("can plot on sub-second time scale", {
info <- save_outputs(g, "point-size-alpha2")
expect_equivalent(info$data[[1]]$x, as.numeric(d$x))
})


test_that("can flip axes", {
# https://github.com/ropensci/plotly/issues/1074
p <- ggplot(diamonds[sample(nrow(diamonds), 1000),]) +
geom_point(aes(carat, price)) +
expand_limits(y = 0) +
coord_flip()

info <- save_outputs(p, "point-flip")
expect_equivalent(info$layout$xaxis$title, "price")
expect_equivalent(info$layout$yaxis$title, "carat")
})

0 comments on commit 6e93169

Please sign in to comment.