I have a Shiny app with several plotly visualisations. The user is allowed to choose several products and I would like each product to have the same unique color throughout the entire app. One of my visualisations could e.g. look like this:
plot_ly(df, x = variable, y=value, type = "bar", color = Product, hoverinfo = "text",
colors = colpal, text = paste0(df$value,"%")) %>%
layout(xaxis=ax, yaxis=yx, legend=list(x=1, y = 0.5))
Is it possible to make sure that the first level of Product ALWAYS get the first value of colpal?
In ggplot I think this can be achieved by specifying the color pallette like this:
c("Product A" = "#00AADC", "Product B" = "#843532","Product C" = "#2C5481", "Product D" = "#CADFE1")
But this doesnt seem to work in plotly.
Any help would be greatly appreciated.
EDIT: Sample dataset
Product variable value
1 Product A DDD 24
2 Product B DDD 22
3 Product C DDD 35
4 Product D DDD 19
5 Product A Brand attention 29
6 Product B Brand attention 27
7 Product C Brand attention 27
8 Product D Brand attention 18
So I would like e.g. Product A to take on the same color everytime.