I am able to plot a geom_bar as I want but when I try to wrap it with the ggplotly
function it does not work. Anyone know a trick to make it work?
library(ggplot2)
library(plotly)
# My df dataset
a=runif(10, min = 0, max = 1)
b=runif(10, min = -1, max = 0)
df=data.frame("p"=c(a,b),
"g"=rep(c("a","b"),each=10),
"type"=c(letters[1:10],letters[1:10]))
# Build the g plot
g <- ggplot(df,
aes(x = as.factor(type), y = p, fill=g)) +
geom_bar(data=df[df$g == "a",] ,stat = "identity") +
geom_bar( data=df[df$g == "b",] ,stat = "identity") +
coord_flip() +
scale_y_continuous(breaks = seq(-1, 1, 0.25),
labels = paste0(abs(seq(-1, 1, 0.25)))) +
xlab("") +
theme_bw()
# plot it the regular way
g
# plot it the ggplotly way
ggplotly(g)