Reputation: 145
I have a problem with R Plotly package:
When I would like to plot a barplot with a minus Y values, it creates wrong plot.
Here is the example:
dane<-data.frame(x=1:10,y=seq(-5,4),g=rep(c('A','B'),each=5))
dane$x<-as.factor(dane$x)
ggplot(data=dane,aes(x=x,y=y,fill=g)) +
geom_bar(stat='identity', position = "identity")
ggplotly()
When I just simple plot with ggplot (without plotly), everything is fine:
ggplot(data=dane,aes(x=x,y=y,fill=g)) +
geom_bar(stat='identity', position = "identity")
Is it a bug? How can I fix it?
Upvotes: 3
Views: 526
Reputation: 9836
But if you are open to use native plotly
, this would give you the result you want:
library(dplyr)
dane_p <- dane %>% filter(g == "A")
dane_p2 <- dane %>% filter(g == "B")
p <- plot_ly(data=dane_p,
x = x,
y = y,
name = "A",
type = "bar")
p2 <- add_trace(p,
data=dane_p2,
x = x,
y = y,
name = "B",
type = "bar")
p2
Upvotes: 1
Reputation: 10352
It´s a known bug: http://community.plot.ly/t/inversion-negative-values-in-ggplotly/875.
Even the newest development version did no fix for this, I just tried this. So you can follow the issue on: https://github.com/ropensci/plotly/issues/560
Upvotes: 2