Skip to content

geom_bar(stat='identity') has problems with negative values #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cpsievert opened this issue Apr 23, 2016 · 10 comments
Closed

geom_bar(stat='identity') has problems with negative values #560

cpsievert opened this issue Apr 23, 2016 · 10 comments

Comments

@cpsievert
Copy link
Collaborator

http://community.plot.ly/t/inversion-negative-values-in-ggplotly/875

d <- data.frame(
    x = LETTERS[1:10], 
    y = -5:4, 
    g = rep(c('A','B'), each = 5)
)

p <- ggplot(data = d, aes(x = x, y = y, fill = g)) +
    geom_bar(stat='identity')
ggplotly(p)
@timelyportfolio
Copy link
Collaborator

timelyportfolio commented May 4, 2016

Any clues here? Happy to work on this. I tracked to here, and everything looks fine.

@cpsievert
Copy link
Collaborator Author

This is the source of the problem (that subtraction is essentially assuming positive ymin/ymax values)

@cpsievert
Copy link
Collaborator Author

We'll probably need to switch from barmode='stacked' to 'relative' to fix this issue -- plotly/plotly.js#517

@timelyportfolio
Copy link
Collaborator

timelyportfolio commented Jun 14, 2016

Just in case somebody needs this before we fix, we can accomplish with plot_ly.

plot_ly(
  data = d,
  x = x,
  y = y,
  color = g,
  type = "bar"
) %>%
  layout(
    xaxis = list(type="category", categoryorder="category ascending")
  )

image

@fabiangehring
Copy link

+1, already an idea when this one will be fixed?

@taylorfturner
Copy link

Looks like I'm not the only one who has issue with this . . . Any update on the fix? Thanks!

@fabiangehring
Copy link

fabiangehring commented Jan 3, 2017

Unfortunately @timelyportfolio 's workaround does not work for orientation = 'h'

d <- data.frame(
x = LETTERS[1:10],
y = -5:4,
g = rep(c('A','B'), each = 5)
)

plot_ly(
data = d,
x = ~y,
y = ~x,
color = ~g,
type = "bar",
orientation ='h'
) %>%
layout(
xaxis = list(type="category", categoryorder="category ascending")
)

@cortinah
Copy link

Any updates regarding a fix for the negative bars turning positive? thank you very much

@lwasser
Copy link

lwasser commented Mar 14, 2017

hello! i am having the same issue. curious about whether a fix may be in the works. I use this with my class!

@zhdanchik
Copy link

Hello, I'm have the same problem... UP this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants