Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 641
Add support for alternative axis sides in ggplotly#813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
1ae04afbb7e07bb5bbc2a369b76094ce05b4edf8e821c57124379260cbd3077304a1abebb135cb82036d92ba0eb31c21c4f08fc47347cd3e00f5bdad3527db1a3941e1f6a55e523a860File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| context("Axis moving") | ||
| expect_traces <- function(gg, n.traces, name){ | ||
| stopifnot(is.numeric(n.traces)) | ||
| L <- save_outputs(gg, paste0("axis-", name)) | ||
| all.traces <- L$data | ||
| no.data <- sapply(all.traces, function(tr) { | ||
| is.null(tr[["x"]]) && is.null(tr[["y"]]) | ||
| }) | ||
| has.data <- all.traces[!no.data] | ||
| expect_equal(length(has.data), n.traces) | ||
| list(data = has.data, layout = L$layout) | ||
| } | ||
| p <- ggplot(mtcars, aes(x=mpg, y=wt)) + | ||
| geom_point() | ||
| test_that("Axis position moves to top", { | ||
| p <- p + scale_x_continuous(position="top") | ||
| info <- save_outputs(p, "axis_move_top") | ||
| expect_equal(length(info$data), 1) | ||
| expect_identical(info$layout$xaxis$side, "top") | ||
| }) | ||
| test_that("Axis position moves to right", { | ||
| p <- p + scale_y_continuous(position="right") | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The axis currently isn't shown because this PR hasn't yet addressed the issue of adding space for axis ticks/text in the right margin (and removing from the left) as is done here ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, thanks for the tip | ||
| info <- save_outputs(p, "axis_move_right") | ||
| expect_equal(length(info$data), 1) | ||
| expect_identical(info$layout$yaxis$side, "right") | ||
| }) | ||
| test_that("Axis position moves to top (facets)", { | ||
| p <- p + scale_x_continuous(position="top") + facet_wrap(~carb) | ||
| info <- save_outputs(p, "axis_move_top_facet") | ||
| expect_equal(length(info$data), 6) | ||
| expect_equal(info$layout$xaxis$anchor, "y") | ||
| expect_identical(info$layout$xaxis$side, "top") | ||
| }) | ||
| test_that("Axis position moves to top (facets)", { | ||
| p <- p + scale_y_continuous(position="right") + facet_wrap(~carb) | ||
| info <- save_outputs(p, "axis_move_right_facet") | ||
| expect_equal(length(info$data), 6) | ||
| expect_equal(info$layout$yaxis$anchor, "x3") | ||
| expect_identical(info$layout$yaxis$side, "right") | ||
| }) | ||
| test_that("Axis positions stay at bottom and left", { | ||
| info <- save_outputs(p, "axis_stay") | ||
| expect_equal(length(info$data), 1) | ||
| expect_identical(info$layout$xaxis$side, "bottom") | ||
| expect_identical(info$layout$yaxis$side, "left") | ||
| expect_equal(info$layout$xaxis$anchor, "y") | ||
| expect_equal(info$layout$yaxis$anchor, "x") | ||
| }) | ||
| test_that("Axis positions stay at bottom and left (facet)", { | ||
| p <- p + facet_wrap(~carb) | ||
| info <- save_outputs(p, "axis_stay_facet") | ||
| expect_equal(length(info$data), 6) | ||
| expect_identical(info$layout$xaxis$side, "bottom") | ||
| expect_identical(info$layout$yaxis$side, "left") | ||
| expect_equal(info$layout$xaxis$anchor, "y2") | ||
| expect_equal(info$layout$yaxis$anchor, "x") | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a magic number. I don't think ticklen can vary dynamically so it has to be large enough to accomodate large and small window sizes. It'll be too long for small window sizes but if it's extreme the user can adjust it using
p %>% layout(xaxis=list(ticklen=10), xaxis2=list(ticklen=10), ...).I'll log an issue on the plotly.js github to see if it would be possible to have ticklen optionally be a proportion of the plot rather than strictly pixels, but otherwise it's a necessary evil