Plotly R order legend entries

Viewed 11290

Is it possible to order the legend entries in R?

If I e.g. specify a pie chart like this:

  plot_ly(df, labels = Product, values = Patients, type = "pie",
          marker = list(colors = Color), textfont=list(color = "white")) %>%
    layout(legend = list(x = 1, y = 0.5))

The legend gets sorted by which Product has the highest number of Patients. I would like the legend to be sorted in alphabetical order by Product.

Is this possible?

1 Answers
Related