plotly / plotly/plotly.R

Scatter points at wrong coordinates when combining multicategory axis and colour

Open
#1,834 1 comment 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,

When combining a multicategory axis and colour coding in a scatter plot, the mapping of the points seem to go wrong.
In p2 in the example below, the points appear at coordinates that are not in the data.
The problem can be resolved by first ordering the data (p4).

library(plotly)
d <- data.frame(
  l1 = letters[11:15],
  l2 = c('a', 'a', 'a', 'a', 'b'),
  y = 1:10,
  col = LETTERS[11:15],
  stringsAsFactors = F
)
p1 <- plot_ly(
  data = d,
  x = list(~l2, ~l1),
  y = ~y,
  # color = ~col,
  type = 'scatter',
  mode = 'markers'
)
p2 <- plot_ly(
  data = d,
  x = list(~l2, ~l1),
  y = ~y,
  color = ~col,
  type = 'scatter',
  mode = 'markers'
)
d <- d[order(d$l1), ]
p3 <- plot_ly(
  data = d,
  x = list(~l2, ~l1),
  y = ~y,
  # color = ~col,
  type = 'scatter',
  mode = 'markers'
)
p4 <- plot_ly(
  data = d,
  x = list(~l2, ~l1),
  y = ~y,
  color = ~col,
  type = 'scatter',
  mode = 'markers'
)

subplot(p1, p2, p3, p4, nrows = 2, margin = .07) %>% 
  layout(annotations = list(
    list(x = 0.1 , y = 1.05, text = "unordered/uncolored", showarrow = F, xref='paper', yref='paper'),
    list(x = 0.9 , y = 1.05, text = "unordered/colored", showarrow = F, xref='paper', yref='paper'),
    list(x = 0.1 , y = .45, text = "ordered/uncolored", showarrow = F, xref='paper', yref='paper'),
    list(x = 0.9 , y = .45, text = "ordered/colored", showarrow = F, xref='paper', yref='paper')
  )
)

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 provided R reproducible example and compare the unordered/colored scatter plot with the other panels. Trace the scatter handling for multicategory axes combined with color; done means points remain at the coordinates in the input data without requiring prior ordering.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.