Hi
I am trying to change the color of the individual bars of a waterfall chart, more specifically the first and the last bar, I want it to be blue and yellow respectively. So in the below graph, Group 1 has to be blue and Group 2 has to be yellow.
Here is the code to generate the above graph:
library(plotly)
df <- data.frame(Rank = 1:7, Variable = c("Group 1","A","B","C","D","E","Group 2"),
Value = c(10,2,2,2,1,1,20),
measure = c("relative","relative","relative","relative","relative","relative","total"),
colour = c("yellow","green","green","green","green","green","blue"))
df$Variable <- factor(df$Variable, levels = unique(df$Variable))
df$text <- as.character(round(df$Value,2))
df$Factor <- as.numeric(df$Variable)
plot_ly(df, name = "20", type = "waterfall", measure = ~measure,
x = ~Variable, textposition = "outside", y= ~Value, text =~paste0('$',text),
hoverinfo='none',cliponaxis = FALSE,
connector = list(line = list(color= "rgb(63, 63, 63)"))
) %>%
layout(title = "",
xaxis = list(title = ""),
yaxis = list(title = "",tickprefix ='$'),
autosize = TRUE,
showlegend = FALSE
)
Any help would be really appreciated.