Geom errorbar issure 1751 by trekonom · Pull Request #1779 · plotly/plotly.R · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions R/layers2traces.R
1 change: 1 addition & 0 deletions tests/figs/errorbar/errobar-flipped-aes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/figs/errorbar/errobar-no-aes-y.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions tests/testthat/test-geom-errorbar-flipped-aes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
context("Errorbar")

test_that("geom_errobar is rendered with flipped aes", {

df <- dplyr::group_by(iris, Species)
df <- dplyr::summarise_if(df, is.numeric, list(m = mean, q1 = ~ quantile(.x, .25), q3 = ~ quantile(.x, .75)))
gp <- ggplot(df, aes(y = Species, xmin = Sepal.Width_q1, xmax = Sepal.Width_q3)) +
geom_errorbar()

L <- plotly_build(gp)

# Tests
# errobar is rendered
expect_doppelganger(L, "errobar-flipped-aes")
# xmin and xmax equal to ggplot
expect_equivalent(L[["x"]][["data"]][[1]][["x"]] + L[["x"]][["data"]][[1]][["error_x"]][["array"]],
ggplot_build(gp)$data[[1]]$xmax)

expect_equivalent(L[["x"]][["data"]][[1]][["x"]] - L[["x"]][["data"]][[1]][["error_x"]][["arrayminus"]],
ggplot_build(gp)$data[[1]]$xmin)
# xmin and xmax equal to data
expect_equivalent(L[["x"]][["data"]][[1]][["x"]] + L[["x"]][["data"]][[1]][["error_x"]][["array"]],
df$Sepal.Width_q3)

expect_equivalent(L[["x"]][["data"]][[1]][["x"]] - L[["x"]][["data"]][[1]][["error_x"]][["arrayminus"]],
df$Sepal.Width_q1)

})
36 changes: 36 additions & 0 deletions tests/testthat/test-geom-errorbar-issue-1751.R