Share the Gallery !Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Plotly‘s way to label color is very much inspired by the semantics of ggplot2. It is a powerful tool but you need to grasp the logic behind it. Here are 5 examples inspired by the plotly’s user guide explaining how you can label colors with plotly!
For every example, you first need to charge the plotly library and have a look at the iris dataset:

 

1 — / Hand chosen colors.

#121 Manage colors in plotly

a
This is the most basic way to set the color: you choose the color point by point or give one color for all the points. It works like a classic R graph. Add the color argument IN the marker argument because it does not depend of another variable!
There are several formats available with plotly for color names :
        – hex (e.g. ‘#d3d3d3’)
        – rgb (e.g. ‘rgb(255, 0, 0)’)
        – rgba (e.g. ‘rgb(255, 0, 0, 0.5)’)
        – hsl (e.g. ‘hsl(0, 100%, 50%)’)
        – hsv (e.g. ‘hsv(0, 100%, 100%)’)
        – named colors (full list here)
a
a
2 — / Qualitative color mapping

#121 Manage colors in plotly#121 Manage colors in plotly

a
If a ordinal variable (AKA a non-ordered factor variable) is assigned to the coloR argument, then a qualitative color palette is used by default. So we put the argument color OUT of the marker arguments!
If you want to change the default palette, it’s recommended that you provide a RColorBrewer qualitative pallette name (e.g., “Set1” or “Accent”) to the colorS argument. See graph #38 to see the existing palettes.
a
a
3 — / Sequential color mapping

#121 Manage colors in plotly#121 Manage colors in plotly

 

If either a numeric or an ordered factor is mapped to the coloR argument, plot_ly() applies a sequential color scale by default.

You can also change the palette, giving the starting and ending colors to the colorS argument.

 


Not what you are looking for? Make a new search!


Leave a Reply

2 Comments on "#121 Manage colors with plotly"

Notify of
avatar
Sort by:   newest | oldest | most voted
Kathy
Guest

How to set up background color for R Plotly Heat Map?

wpDiscuz