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

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)
2 — / Qualitative color mapping

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

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.
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!

3D abline add aggregate animation arrows at axis barplot basics beside bg border boxplot boxwex breaks bty cex cex.axis circular plot cmdscale col color Colors cor cut d3.js dataArt dendrogram density dist factor font ggplot2 hclust hist Histograms horiz hsv ifelse Igraph image ImageMagick Important ! inset jitter labels las lattice layout leafletR legend legend.text levelplot levels library lines lm lty lwd main map Maps mar mfrow mfrox mgp Miscellaneous model mtext mtxt names nlevels oma order package par paste PCA pch pie plot plotly points polygon predict pt.cex pty R radarchart rect reorder rgb rgl Ring scatterplot segments stacked-area table tag_ tag_for_slider testnumber1 text tick Time series title toto tutu type VennDiagram violin-plot width wordcloud xaxt xlab xlim xyplot yaxt ylab ylim zetag

You can search a media by theme with the tag cloud above.

Leave a Reply

2 Comments on "#121 Manage colors with plotly"

Notify of

Sort by:   newest | oldest | most voted
3 months 25 days ago

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