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 is 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:
Hi ! unfortunately, the marker argument controls color for markers as well lines in this case. So the only way for the points and lines to have different colors is to have separate traces using add_trace()
Example:
library(plotly)
df <- data.frame(x = 1:10,
y = sample(10:30, size = 10))
plot_ly(df, x = x, y = y, mode = "markers", marker = list(color = "red", size = 10)) %>%
add_trace(x = x, y = y, mode = "lines", marker = list(color = "green"))
I believe doing what should change the color of the line as well points not just the points (markers). Works for me. Are you seeing otherwise? Can you share a screenshot?
Unfortunately doesn’t seem like the color argument used in line takes multiple colors. If you keep the group argument as an ordered factor, I think plot_ly() will keep the color scheme consistent across charts.