plotly / plotly.R

An interactive graphing library for R
https://plotly-r.com
Other
2.57k stars 626 forks source link

Paired brewer palette does not behave as expected #1120

Closed Shians closed 5 years ago

Shians commented 7 years ago

When using the "Paired" palette the colours do not appear as they do in ggplot2. It also does not appear to respect the paired colours property of the palette regarding successive factor levels.

data(iris)
plotly::plot_ly(data = iris,
    x = ~Sepal.Length, y = ~Petal.Length, color = ~Species, colors = "Paired")

ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, col = Species)) +
    geom_point() +
    scale_color_brewer("Paired")

It can be made to work with

plotly::plot_ly(data = iris,
    x = ~Sepal.Length, y = ~Petal.Length, color = ~Species,
    colors = RColorBrewer::brewer.pal(3, "Paired"))
cpsievert commented 5 years ago

It also does not appear to respect the paired colours property of the palette regarding successive factor levels.

I don't quite follow -- can you make an argument that the ggplot2 behavior is objectively better?

Shians commented 5 years ago

This is specifically regarding the "Paired" palette

qual-500x127

Based on the name I assume the colours are for presenting data in pairs, therefore having similar pairs of colours shown above. This can be useful for data as presented here.

screen shot 2019-01-25 at 12 25 49 pm

with the effect that meals have similar colours and the numbering has similar intensity. In ggplot2 this is achieved by ordering your paired levels to be adjacent to each other. In plot_ly it requires going around the canonical interface for accessing "Paired". Obviously the choice is totally arbitrary for the palettes with no structure.

cpsievert commented 5 years ago

Both of those plot_ly() code blocks produce the same result for me, is this not what you'd expect?

screen shot 2019-01-24 at 7 51 27 pm
Shians commented 5 years ago

On my MacOS 10.13.6 system with Plotly 4.8.0, running

plotly::plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species, colors = "Paired")

shows

screen shot 2019-01-25 at 1 47 30 pm

I think back when I submitted the issue the behaviour with 3 levels was to pick colours from the two ends and centre of a palette.

cpsievert commented 5 years ago

Ohhh, this is actually due to a change in scales::col_factor() -- if you install the Github version you'll get the result in https://github.com/ropensci/plotly/issues/1120#issuecomment-457426736

cpsievert commented 5 years ago

Closing since the new scales gives you the behavior you'd expect, right?