plotly / plotly/plotly.R

Wrong width of bar in bar plots

Open
#1,776 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I would have expected a single bar with a width of 0.05 here:

library(plotly)

plot_ly(
  type = 'bar',
  x = 0.2,
  y = 10,
  width = 0.05
) %>% 
layout(
  xaxis=list(range=c(0,1))
)

Instead, I get a single bar with width 0.6 (and not 0.05).

Similarily, I would have expected two bars, each of width 0.05 here:

plot_ly(
  type = 'bar',
  x = c(0.2, 0.5),
  y = c(10, 8),
  width = 0.05
) %>% 
layout(
  xaxis=list(range=c(0,1))
)

Instead, it shows two bars, but not of width 0.05.

Only if I'm plotting 4 bars (or more) do I get the correct width (of 0.05) for each:

plot_ly(
  type = 'bar',
  x = c(0.2, 0.5, 0.6, 0.7),
  y = c(10, 8, 7, 3),
  width = 0.05
) %>% 
layout(
  xaxis=list(range=c(0,1))
)

Checking with a Javascript codepen, using

var trace0 = {
  type: 'bar',
  x: [0.2],
  y: [10],
  width: 0.05
}

var layout = {
  xaxis: {range: [0, 1]}
}

var data = [trace0]

Plotly.newPlot('myDiv', data, layout);

does give the expected result.

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 reproducing the three R examples using plot_ly() and layout(), then compare their bar widths with the JavaScript CodePen example. Trace how the R inputs are translated into the bar plot entry point; done means one- and two-bar plots honor width = 0.05 as the four-bar plot and JavaScript example do.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.