plotly / plotly/plotly.R

Multicategory axis support

Open
#1,597 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

Hi,

I am trying to use multicategory axes and get very inconsistent behavior. This is what I tested so far:

Bar charts:

I need to manually supply type = "multicategory" to the axis. This is opposed to what I have read for the python api, where this will happen automatically if your traces have arrays. see here

reprex

library(plotly)
two_f <- rbind(
  c("BB+", "BB+", "BB+", "BB", "BB", "BB"),
  c(16, 17, 18, 16, 17, 18)
)
p <- plot_ly() %>% 
  add_bars(x=two_f,y=c(1,2,3,4,5,6)) %>% 
  layout(barmode="relative")
p # no multicategory axis
p_multi <- p %>% layout(xaxis=list(side = "top", type = "multicategory"))
p_multi # multicategory axis on top

Heatmaps:

Thanks to michaelbabyn, I know how to create a multicategory x-axis for a heatmap. However, as opposed to bar charts, making a multicategory y-axis crashes, and trying to move the x-axis on top of the chart also crashes.

reprex

library(plotly)
q <- plot_ly() %>% 
  add_heatmap(
    x=rbind(c('aa', 'aa', 'bb', 'bb', 'cc', 'cc'), c(1,2,3,4,5,6)),
    y=c(1,2,3,4,5,6),
    z = array(seq(1,10, length.out = 36), c(6,6)))
q # this works
q_y <- plot_ly() %>% 
  add_heatmap(
    x=c(1,2,3,4,5,6),
    y=rbind(c('aa', 'aa', 'bb', 'bb', 'cc', 'cc'), c(1,2,3,4,5,6)),
    z = array(seq(1,10, length.out = 36), c(6,6))) 
## this would crash the Rstudio session:
## it should render something like https://codepen.io/michaelbabyn/pen/pMOOwM?editors=0010
# q_y

## this also breaks the session:
qx_top <- q %>% layout(xaxis=list(side = "top"))
# qx_top

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied plot_ly(), add_bars(), add_heatmap(), and layout() reproductions in RStudio, comparing the bar and heatmap cases. Trace the multicategory axis handling for x and y axes; done means the examples render consistently, including the heatmap y-axis and top-positioned x-axis, without crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.