plotly stacked area graph custom colours from named vector

Hi, I am trying to use custom colours with a dataset in Plotly. The named vector works from a line graph and other graphs, but doesn't for the stacked area graph. Any ideas?

library(plotly)
library(tidyverse)
library(palmerpenguins) # for the dataset

penguins_cols <- c("Adelie" = "blue",
                   "Gentoo" = "red",
                   "Chinstrap" = "green")

# works for line graphs
plot_ly(penguins,
        colors = penguins_cols) %>%
  add_trace(x = ~bill_length_mm,
            y = ~bill_depth_mm,
            color = ~species,
            type = "scatter",
            mode = "lines+markers")


# doesn't work for area graphs
plot_ly(penguins,
        colors = penguins_cols) %>%
  add_trace(x = ~bill_length_mm,
            y = ~bill_depth_mm,
            fillcolor = ~species,
            mode = "none",
            stackgroup = 'one')


Answer here: r - plotly stacked area graph custom colours from named vector - Stack Overflow

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.