Skip to content

Bar chart x-axis factor order wrong #242

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

Closed
13bzhang opened this issue Jul 31, 2015 · 2 comments
Closed

Bar chart x-axis factor order wrong #242

13bzhang opened this issue Jul 31, 2015 · 2 comments

Comments

@13bzhang
Copy link
Contributor

When I was writing tests for #241, I came across this problem where the bar chart x-axis factor level order is wrong.

R code:

set.seed(23049)
long_items <- data.frame(cat1 = sample(x = LETTERS[1:10], 
                                  size = 100, replace = TRUE),
                    cat2 = sample(x = LETTERS[1:10],
                                  size = 100, replace = TRUE))
p <- ggplot(long_items, aes(cat1, fill=cat2)) + geom_bar(position="dodge")
py$ggplotly(p)

ggplot2 figure:
abc_ggplot2

Note the figure above has the x-axis in alphabetical order.

Plotly figure (based on PR #241): https://plot.ly/~13bzhang/1365/count-vs-cat1/
abc_plotly_master

Now the x-axis is not in alphabetical order.

@cpsievert @chriddyp @mkcor

@cpsievert
Copy link
Collaborator

The x-axis ordering is controlled by the order in which values first appear in the trace data:

l <- plotly_build(p)
# notice how this matches the x-axis ordering
unique(unlist(lapply(l$data, "[[", "x")))
#>  [1] A B C E F I G H J D
#> Levels: A B C D E F G H I J

It seems like I should be able to control this ordering by setting the range of the axis, but this doesn't do what I want, any ideas @chriddyp @cldougl?

l$layout$xaxis$range <- LETTERS[1:10]
l

@cpsievert
Copy link
Collaborator

This should be fixed in f1900cc. Let us know if you still have problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants