Categoryorder not working when specifying plot type
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
When using the category order parameter, no plot is generated if the plot type is specified in the plot_ly call:
p <- plotly::plot_ly(type = 'bar')
colNames <- names(iris)
colNames <- colNames[-which(colNames == 'Species')]
for(trace in colNames){
p <- p %>% plotly::add_trace(data= iris, x = ~ Species, y = as.formula(paste0("~`", trace, "`")), name = trace)
}
p %>% layout(xaxis = list(categoryorder='total descending'))
With the following warning, which I don't understand since I'm not combining discrete and non-discrete data in the same axis:
Warning message:
Can't display both discrete & non-discrete data on same axis
If I specify the type in add_trace instead of the plot, then it works correctly and the warning is gone:
p <- plotly::plot_ly()
colNames <- names(df)
colNames <- colNames[-which(colNames == 'Species')]
for(trace in colNames){
p <- p %>% plotly::add_trace(type = 'bar', data= iris, x = ~ Species, y = as.formula(paste0("~`", trace, "`")), name = trace)
}
p %>% layout(xaxis = list(categoryorder='total descending'))
Maybe this is the intended behavior? If so, why does specifying the type in the traces works and not in the plot? The warning seems unclear to me.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied R reproduction with iris and compare plot_ly(type = 'bar') against add_trace(type = 'bar'). Trace how plot_ly and add_trace propagate the type and how layout(xaxis = list(categoryorder = 'total descending')) handles the resulting traces. Done means the reproduction no longer emits the warning and category ordering works consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100