Scaling Colors for plot_ly bar graph?

Hello!

Been trying to figure out a fix but not sure if there’s an easy way to do this.

plot_ly appears to allow color scales for scatter plots, so that higher values are colored differently. Is there a way to apply a similar color scale to a plot_ly bar graph?

For instance, if I wanted bars with values closer to 1 colored green, but values closer to 0 colored as red, would that be possible with the “color” argument?

Thanks for the help!

Found a work-around with ggplotly. Still seems impossible with base plot_ly command.

a <- ggplot(test.players, aes(x = Player,
                     y = Average.Points,
                     fill = Average.Points)
    )
b <- a + geom_bar(stat = "identity")
c <- b + scale_fill_gradientn(colors = c("red", "green"))
ggplotly(c)

Hi

That should be possible in the actual plot_ly (4.5.2) with 'colorRamp’
for example:

p<-dat%>%
group_by(abc)%>%
plot_ly(x=~x, y = ~y)%>%
add_markers(color=~QFaktor, symbol=~Teil,
colors = colorRamp(c(“red”, “darkorange”, “green”)),
text=~paste0('ID: ',id))