Adding 'name' parameter to plot_ly() function removes factor ordering.
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
We sometimes use the 'name' parameter within the plot_ly() function to add a suffix to the values shown in a legend. Values in the legend are shown because a variable (legend variable) is used for the 'color' parameter in plot_ly().
Since a few days/weeks, using this method to add a suffix leads to the ordering of 'legend variable' to switch to alphabetical order instead of its original factor levels.
I added an example below.
library(plotly)
library(lubridate)
factor <- factor(x = c('bbb', 'ccc', 'aaa'), levels = c('bbb', 'ccc', 'aaa'))
number <- c(1,2,3)
date <- c(ymd(20170101), ymd(20170202), ymd(20170303))
levels(factor)
df <- data.frame(letter = factor, number = number, date = date)
levels(df$letter)
plot_ly(df, x = ~number, y = ~date, type = 'bar', color = ~letter)
plot_ly(df, x = ~number, y = ~date, type = 'bar', color = ~letter, name = 'ff')
plot_ly(df, x = ~number, y = ~date, type = 'bar', color = ~letter, name = c('asd', 'ff', 'ss'))
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 reproducible R examples using plot_ly() with color = ~letter, first without name and then with each name form. Trace the plot_ly() handling of factor levels and legend names; done means the legend preserves the factor order bbb, ccc, aaa in all shown cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- plotly, r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100